python - 在 django 应用程序中集成 pinax 通知失败

标签 python django notifications pinax

我正在使用 django-1.10,并希望使用 pinax-notifications-4.0 为我的应用程序实现一些通知行为。

我正在关注quickstart将其包含到 INSTALLED_APP

INSTALLED_APPS = [
    # ...
    "pinax.notifications",
    # ...
]

然后是 usage指南。

首先是在 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:模型类 django.contrib.sites.models.Site 未声明显式 app_label 并且不在 INSTALLED_APPS 中的应用程序中。

然后我尝试将 INSTALLED_APPS 中的 pinax.notifications 更改为 pinax-notifications。服务器给我产生了这个错误:ImportError:没有名为 pinax-notifications 的模块

如何做到这一点?

最佳答案

我能够通过更改 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)

关于python - 在 django 应用程序中集成 pinax 通知失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41311399/

相关文章:

python - csv.DictWriter 定界符设置为空格表示 ""中的文本

python - 根据值在 Admin 中自定义 Django 表单字段

python - 更改列表中字典中的键值

Django DRY - 如何使用相同的模板简化类似的 View ?

c++ - 处理 "depends on non-NOTIFYable properties"警告

laravel - 向特定用户发送推送通知 - Laravel

python - blockmanage() 采用 1 个位置参数,但在将数组传递给函数时给出了 36 个位置参数

python - django 两个 ModelForms 在一个模板上具有相同的字段名称

javascript - 道场/请求 PUT 方法不起作用

Android 通知 FLAG_AUTO_CANCEL 不工作