Skip to content

Commit 87dbe98

Browse files
committed
Add possibility to specify recipient model
1 parent b5aca84 commit 87dbe98

File tree

7 files changed

+19
-7
lines changed

7 files changed

+19
-7
lines changed

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
History
33
=======
44

5+
not released yet
6+
----------------
7+
8+
* Add ``PYNOTIFY_RECIPIENT_MODEL`` config option
9+
510
0.4.1 (2020-10-12)
611
------------------
712

docs/configuration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ You can configure the library in Django settings. Following options are availabl
2525

2626
Import path to a receiver class.
2727

28+
* ``PYNOTIFY_RECIPIENT_MODEL`` (default: ``settings.AUTH_USER_MODEL``)
29+
30+
Model used for recipient's foreign key on ``Notification`` model. Please note, that if you change this setting after
31+
initial migration has been aplied, you must migrate the model manually.
32+
2833
* ``PYNOTIFY_RELATED_OBJECTS_ALLOWED_ATTRIBUTES`` (default: ``{'get_absolute_url', }``)
2934

3035
A set of related object's attributes that can be used in notification template(s).

pynotify/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Settings:
1111
'CELERY_TASK': 'pynotify.tasks.notification_task',
1212
'ENABLED': True,
1313
'RECEIVER': 'pynotify.receivers.SynchronousReceiver',
14+
'RECIPIENT_MODEL': django_settings.AUTH_USER_MODEL,
1415
'RELATED_OBJECTS_ALLOWED_ATTRIBUTES': {'get_absolute_url', },
1516
'STRIP_HTML': False,
1617
'TEMPLATE_CHECK': False,

pynotify/migrations/0001_initial.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Generated by Django 2.2rc1 on 2019-03-20 11:24
22

3-
from django.conf import settings
43
from django.db import migrations, models
54
import django.db.models.deletion
65

6+
from pynotify.config import settings
7+
78

89
class Migration(migrations.Migration):
910

1011
initial = True
1112

1213
dependencies = [
13-
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
migrations.swappable_dependency(settings.RECIPIENT_MODEL),
1415
('contenttypes', '0002_remove_content_type_name'),
1516
]
1617

@@ -24,7 +25,7 @@ class Migration(migrations.Migration):
2425
('is_read', models.BooleanField(default=False, verbose_name='is read')),
2526
('is_triggered', models.BooleanField(default=False, verbose_name='is triggered')),
2627
('recipient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
27-
related_name='notifications', to=settings.AUTH_USER_MODEL,
28+
related_name='notifications', to=settings.RECIPIENT_MODEL,
2829
verbose_name='recipient')),
2930
],
3031
options={

pynotify/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33

44
from chamber.models import SmartModel, SmartModelBase, SmartQuerySet
5-
from django.conf import settings as django_settings
65
from django.contrib.contenttypes.fields import GenericForeignKey
76
from django.contrib.contenttypes.models import ContentType
87
from django.core.serializers.json import DjangoJSONEncoder
@@ -187,7 +186,7 @@ class Notification(BaseModel, metaclass=NotificationMeta):
187186
extra_data: JSON serialized dictionary with extra data.
188187
"""
189188
recipient = models.ForeignKey(
190-
django_settings.AUTH_USER_MODEL,
189+
settings.RECIPIENT_MODEL,
191190
related_name='notifications',
192191
on_delete=models.CASCADE,
193192
verbose_name=_l('recipient'),

requirements_docs.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-r requirements_dev.txt
2-
django>=2.2
2+
beautifulsoup4>=4.8.0
33
celery>=4.2.0
44
django-chamber>=0.5.0
5+
django>=2.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
requirements = [
1515
'beautifulsoup4 ~=4.8.0',
1616
'celery >= 4.2.0',
17-
'django >= 2.2',
17+
'django ~= 2.2',
1818
'django-chamber ~= 0.5.0',
1919
'lxml ~= 4.5.0',
2020
]

0 commit comments

Comments
 (0)