diff --git a/HISTORY.rst b/HISTORY.rst index f027a8d..58ae4fa 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +not released yet +---------------- + +* Add ``PYNOTIFY_RECIPIENT_MODEL`` config option + 0.4.1 (2020-10-12) ------------------ diff --git a/docs/configuration.rst b/docs/configuration.rst index c8453ba..29760da 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -25,6 +25,11 @@ You can configure the library in Django settings. Following options are availabl Import path to a receiver class. +* ``PYNOTIFY_RECIPIENT_MODEL`` (default: ``settings.AUTH_USER_MODEL``) + + Model used for recipient's foreign key on ``Notification`` model. Please note, that if you change this setting after + initial migration has been aplied, you might need to migrate the model manually. + * ``PYNOTIFY_RELATED_OBJECTS_ALLOWED_ATTRIBUTES`` (default: ``{'get_absolute_url', }``) A set of related object's attributes that can be used in notification template(s). diff --git a/pynotify/config.py b/pynotify/config.py index 1a9ee53..f2c1e7e 100644 --- a/pynotify/config.py +++ b/pynotify/config.py @@ -11,6 +11,7 @@ class Settings: 'CELERY_TASK': 'pynotify.tasks.notification_task', 'ENABLED': True, 'RECEIVER': 'pynotify.receivers.SynchronousReceiver', + 'RECIPIENT_MODEL': django_settings.AUTH_USER_MODEL, 'RELATED_OBJECTS_ALLOWED_ATTRIBUTES': {'get_absolute_url', }, 'STRIP_HTML': False, 'TEMPLATE_CHECK': False, diff --git a/pynotify/migrations/0001_initial.py b/pynotify/migrations/0001_initial.py index 93d5f60..47e91ba 100644 --- a/pynotify/migrations/0001_initial.py +++ b/pynotify/migrations/0001_initial.py @@ -1,16 +1,17 @@ # Generated by Django 2.2rc1 on 2019-03-20 11:24 -from django.conf import settings from django.db import migrations, models import django.db.models.deletion +from pynotify.config import settings + class Migration(migrations.Migration): initial = True dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), + migrations.swappable_dependency(settings.RECIPIENT_MODEL), ('contenttypes', '0002_remove_content_type_name'), ] @@ -24,7 +25,7 @@ class Migration(migrations.Migration): ('is_read', models.BooleanField(default=False, verbose_name='is read')), ('is_triggered', models.BooleanField(default=False, verbose_name='is triggered')), ('recipient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, - related_name='notifications', to=settings.AUTH_USER_MODEL, + related_name='notifications', to=settings.RECIPIENT_MODEL, verbose_name='recipient')), ], options={ diff --git a/pynotify/models.py b/pynotify/models.py index d87686b..7fd80db 100644 --- a/pynotify/models.py +++ b/pynotify/models.py @@ -2,7 +2,6 @@ import re from chamber.models import SmartModel, SmartModelBase, SmartQuerySet -from django.conf import settings as django_settings from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.core.serializers.json import DjangoJSONEncoder @@ -187,7 +186,7 @@ class Notification(BaseModel, metaclass=NotificationMeta): extra_data: JSON serialized dictionary with extra data. """ recipient = models.ForeignKey( - django_settings.AUTH_USER_MODEL, + settings.RECIPIENT_MODEL, related_name='notifications', on_delete=models.CASCADE, verbose_name=_l('recipient'), diff --git a/requirements_docs.txt b/requirements_docs.txt index 302c3b5..cfbdcbb 100644 --- a/requirements_docs.txt +++ b/requirements_docs.txt @@ -1,4 +1,6 @@ -r requirements_dev.txt -django>=2.2 -celery>=4.2.0 -django-chamber>=0.5.0 +beautifulsoup4==4.* +celery==4.* +django-chamber==0.* +django==2.* +lxml==4.* diff --git a/setup.py b/setup.py index 10118ac..3106087 100644 --- a/setup.py +++ b/setup.py @@ -11,12 +11,13 @@ with open('HISTORY.rst') as history_file: history = history_file.read() +# keep in sync with requirements_docs.txt requirements = [ - 'beautifulsoup4 ~=4.8.0', - 'celery >= 4.2.0', - 'django >= 2.2', - 'django-chamber ~= 0.5.0', - 'lxml ~= 4.5.0', + 'beautifulsoup4==4.*', + 'celery==4.*', + 'django==2.*', + 'django-chamber==0.*', + 'lxml==4.*', ] setup(