我正在使用django-notification和django-messages项目,并利用django-messages内置的django-notifications集成及其收到消息时的默认通知类型,回复,等
但是,我无法确定如何创建这些默认的NoticeType对象。 django-notification文档建议在management.py文件中使用post_syncdb信号,这就是我为自己的自定义通知所做的事情。我无法在任何代码中的任何地方找到这些通知类型的定义。然而,每次我在新数据库上运行syncdb时,它们都会神奇地出现。
django-messages应用程序创建的通知类型的“label”属性如下:
答案 0 :(得分:0)
django_messages / management.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
这里定义了类型并挂钩到post_syncdb信号。