Reputation: 9443
Im working with django-1.10
and would like to implement some notification behaviour for my application using pinax-notifications-4.0
.
I am following the quickstart for including this to the INSTALLED_APP
INSTALLED_APPS = [
# ...
"pinax.notifications",
# ...
]
then and the usage guide.
First is to create the notice type in 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")
)
Secondly call the handler to create notices after the application is migrated. 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)
finally include the appconfig to the heat.__init__.py
default_app_config = 'heat.apps.HeatConfig'
but when trying to run these:
python manage.py makemigrations pinax.notifications
I got this error: RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Then i try to change the pinax.notifications
to pinax-notifications
in the INSTALLED_APPS
. The server yield me this error: ImportError: No module named pinax-notifications
How to make this work?
Upvotes: 2
Views: 867
Reputation: 8945
For the record, I also encountered this problem and found, as Roel Delos Reyes previously did, that changing the app-name to pinax
(instead of pinax.notifications
as the documentation very-clearly states) appears to have solved the problem.
When I made this change, makemigrations
found all of the migrations.
I'm actually using both "pinax.notifications" and "pinax.templates" (as the documentation for notifications recommends), and I see that both sets of documentation clearly specify pinax.<something>
. I can't explain it ... how could the documentation be that wrong? Twice?
(I'm using Django 1.19 instead of 2.0 for other unrelated reasons, but I don't think that matters.)
Anyhow – "this worked." HTH.™
Important Edit: I subsequently found that both pinax
and pinax.notifications
are needed in INSTALLED_APPS
. Without the latter, migrate
would not apply all of the migrations.
INSTALLED_APPS = [
...
'pinax',
'pinax.notifications',
...
]
I also opened (and have since closed) a trouble-ticket to this effect in the project on GitHub, so please refer to that site, as well.
Upvotes: 0
Reputation: 9443
I was able to solved it by changing the heat.apps.py file
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)
to this.
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)
Upvotes: 2