Skip to content

Commit 0b8b2df

Browse files
committed
Add possibility to specify recipient model
1 parent b5aca84 commit 0b8b2df

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Notification(BaseModel, metaclass=NotificationMeta):
187187
extra_data: JSON serialized dictionary with extra data.
188188
"""
189189
recipient = models.ForeignKey(
190-
django_settings.AUTH_USER_MODEL,
190+
settings.RECIPIENT_MODEL,
191191
related_name='notifications',
192192
on_delete=models.CASCADE,
193193
verbose_name=_l('recipient'),

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)