DjangMessages如何在syncdb期间创建通知类型?

2024-09-28 20:58:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我将同时使用django-notificationdjango-messages项目,并利用django消息中内置的django通知集成,以及接收、回复消息时的默认通知类型

但是,我无法确定这些默认NoticeType对象是如何创建的。django通知文档建议在管理.py文件,这是我为自己的自定义通知所做的。我在任何代码中都找不到定义这些通知类型的任何地方。但每次我在新数据库上运行syncdb时,它们都会神奇地出现。在

由django messages应用程序创建的通知类型的“label”属性如下:

  • 收到的消息
  • 已发送消息
  • 留言已回复
  • 收到的消息
  • 邮件已删除
  • 消息已恢复

Tags: 文件项目对象django代码文档py消息
1条回答
网友
1楼 · 发布于 2024-09-28 20:58:02

django_消息/管理.py公司名称:

from django.db.models import get_models, signals
from django.conf import settings
from django.utils.translation import ugettext_noop as _

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def create_notice_types(app, created_models, verbosity, **kwargs):
        notification.create_notice_type("messages_received", _("Message Received"), _("you have received a message"), default=2)
        notification.create_notice_type("messages_sent", _("Message Sent"), _("you have sent a message"), default=1)
        notification.create_notice_type("messages_replied", _("Message Replied"), _("you have replied to a message"), default=1)
        notification.create_notice_type("messages_reply_received", _("Reply Received"), _("you have received a reply to a message"), default=2)
        notification.create_notice_type("messages_deleted", _("Message Deleted"), _("you have deleted a message"), default=1)
        notification.create_notice_type("messages_recovered", _("Message Recovered"), _("you have undeleted a message"), default=1)

    signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
    print "Skipping creation of NoticeTypes as notification app not found"

https://github.com/arneb/django-messages/blob/master/django_messages/management.py

类型在这里定义,并连接到后同步DB信号。在

相关问题 更多 >