From 6fe8fe6678b9a5006e11312467ee7a609886bf73 Mon Sep 17 00:00:00 2001 From: TheOneAboveAllTitan Date: Sun, 12 Apr 2020 01:17:43 +0530 Subject: [PATCH] [swapper] Removed hardlinks for Notification model #285 --- README.rst | 12 +++++++++++- notifications/admin.py | 4 +++- notifications/base/models.py | 1 - notifications/tests/tests.py | 6 +++++- notifications/views.py | 11 +++++++---- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index d6800db..21aef05 100644 --- a/README.rst +++ b/README.rst @@ -408,7 +408,9 @@ In case you need to customize the notification model in order to add field or customised features that depend on your application, you can inherit and extend the ``AbstractNotification`` model, example: -.. code-block:: python +.. code-block:: python + + #In your_app/models.py from django.db import models from notifications.base.models import AbstractNotification @@ -422,6 +424,14 @@ the ``AbstractNotification`` model, example: class Meta(AbstractNotification.Meta): abstract = False +You will require to define ``NOTIFICATIONS_NOTIFICATION_MODEL`` setting in `setting.py` as follows: + +.. code-block:: python + + # In your_project/settings.py + + NOTIFICATIONS_NOTIFICATION_MODEL = 'your_app.Notification' + Notes ===== diff --git a/notifications/admin.py b/notifications/admin.py index ce34924..a2b60bf 100644 --- a/notifications/admin.py +++ b/notifications/admin.py @@ -1,7 +1,9 @@ ''' Django notifications admin file ''' # -*- coding: utf-8 -*- from django.contrib import admin -from .models import Notification +from swapper import load_model + +Notification = load_model('notifications', 'Notification') class NotificationAdmin(admin.ModelAdmin): diff --git a/notifications/base/models.py b/notifications/base/models.py index c563857..f565a5f 100644 --- a/notifications/base/models.py +++ b/notifications/base/models.py @@ -211,7 +211,6 @@ class AbstractNotification(models.Model): class Meta: abstract = True ordering = ('-timestamp',) - app_label = 'notifications' # speed up notifications count query index_together = ('recipient', 'unread') diff --git a/notifications/tests/tests.py b/notifications/tests/tests.py index 416c96c..ac36956 100644 --- a/notifications/tests/tests.py +++ b/notifications/tests/tests.py @@ -8,6 +8,7 @@ Replace this with more appropriate tests for your application. import json import pytz + from django.conf import settings from django.contrib.auth.models import Group, User from django.core.exceptions import ImproperlyConfigured @@ -17,9 +18,12 @@ from django.test import RequestFactory, TestCase from django.test.utils import CaptureQueriesContext from django.utils import timezone from django.utils.timezone import localtime, utc -from notifications.models import Notification, notify_handler +from notifications.models import notify_handler from notifications.signals import notify from notifications.utils import id2slug +from swapper import load_model + +Notification = load_model('notifications', 'Notification') try: # Django >= 1.7 diff --git a/notifications/views.py b/notifications/views.py index 0864c05..a56aaa5 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -1,18 +1,21 @@ # -*- coding: utf-8 -*- ''' Django Notifications example views ''' -from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error +from distutils.version import \ + StrictVersion # pylint: disable=no-name-in-module,import-error from django import get_version from django.contrib.auth.decorators import login_required from django.forms import model_to_dict from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator +from django.views.decorators.cache import never_cache from django.views.generic import ListView from notifications import settings -from notifications.models import Notification -from notifications.utils import id2slug, slug2id from notifications.settings import get_config -from django.views.decorators.cache import never_cache +from notifications.utils import id2slug, slug2id +from swapper import load_model + +Notification = load_model('notifications', 'Notification') if StrictVersion(get_version()) >= StrictVersion('1.7.0'): from django.http import JsonResponse # noqa