我与django-1.10一起工作,并希望使用pinax-notifications-4.0为我的应用程序实现一些通知行为。
我正在跟踪快速启动,因为它包含了这个到INSTALLED_APP
INSTALLED_APPS = [
# ...
"pinax.notifications",
# ...
]然后是用法指南。
首先是在heat/handler.py中创建通知类型
from pinax.notifications.models import NoticeType
from django.conf import settings
from django.utils.translation import ugettext_noop as _
def create_notice_types(sender, **kwargs):
NoticeType.create(
"heat_detection",
_("Heat Detected"),
_("you have detected a heat record")
)其次,调用处理程序在迁移应用程序之后创建通知。heat.apps.py
from .handlers import create_notice_types
from django.apps import AppConfig
from django.db.models.signals import post_migrate
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
post_migrate.connect(create_notice_types, sender=self)最后,将appconfig包含到heat.__init__.py
default_app_config = 'heat.apps.HeatConfig'但是,当试图运行这些:
python manage.py makemigrations pinax.notifications我得到了一个错误:RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
然后,我尝试将pinax.notifications更改为INSTALLED_APPS中的pinax-notifications。服务器会产生以下错误:ImportError: No module named pinax-notifications
如何使这个工作?
发布于 2016-12-24 09:36:46
我能够通过更改heat.apps.py文件来解决这个问题
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from .handlers import create_notice_types
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
post_migrate.connect(create_notice_types, sender=self)为了这个。
from django.apps import AppConfig
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
from django.db.models.signals import post_migrate
from .handlers import create_notice_types
post_migrate.connect(create_notice_types, sender=self)发布于 2018-02-14 14:55:36
为了记录在案,我也遇到了这个问题,并发现,正如Reyes之前所做的那样,将应用程序名更改为pinax (而不是文档中非常清楚地指出的pinax.notifications )似乎解决了这个问题。
当我做这个更改时,makemigrations发现了所有的迁移。
实际上,我同时使用了"pinax.notifications“和"pinax.templates”(正如通知文档所建议的那样),并且我看到这两组文档都清楚地指定了pinax.<something>。我无法解释..。文件怎么会那样错呢?两次?
(出于其他不相关的原因,我使用Django 1.19而不是2.0,但我认为这并不重要。)
不管怎么说-“这起作用了。”HTH.™
重要编辑:我随后发现INSTALLED_APPS需要pinax和pinax.notifications。如果没有后者,migrate将不会应用所有迁移。
INSTALLED_APPS = [
...
'pinax',
'pinax.notifications',
...
]我还在GitHub上的项目中打开(并且已经关闭)了一张这方面的麻烦票,所以也请参考该网站。
https://stackoverflow.com/questions/41311399
复制相似问题