0

I inherited this code from the previous Software Engineer. I am still new to Python and Django. In my development environment I updated Django to 4.0. I am able to resolve most issues except one for notifications.

The error:

File "C:\Users\da\Desktop\EnvAug10\lib\site-packages\notifications\admin.py", line 8, in <module>
    Notifications = load_model('notifications', 'Notification')
  File "C:\Users\da\Desktop\EnvAug10\lib\site-packages\swapper\__init__.py", line 79, in load_model
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Could not find notifications.PushNotification!

I have installed: django-notifications-hq==1.8.2 notifications==0.3.2

site-packages\notifications\admin.py:

''' Django notifications admin file '''
# -*- coding: utf-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy
from notifications.base.admin import AbstractNotificationAdmin
from swapper import load_model

Notification = load_model('notifications', 'Notification')


def mark_unread(modeladmin, request, queryset):
    queryset.update(unread=True)
mark_unread.short_description = gettext_lazy('Mark selected notifications as unread')


class NotificationAdmin(AbstractNotificationAdmin):
    raw_id_fields = ('recipient',)
    readonly_fields = ('action_object_url', 'actor_object_url', 'target_object_url')
    list_display = ('recipient', 'actor',
                    'level', 'target', 'unread', 'public')
    list_filter = ('level', 'unread', 'public', 'timestamp',)
    actions = [mark_unread]

    def get_queryset(self, request):
        qs = super(NotificationAdmin, self).get_queryset(request)
        return qs.prefetch_related('actor')


admin.site.register(Notification, NotificationAdmin)

I do have a PushNotification model in my notification app:

from django.contrib import admin
from notification.models import PushNotification, EMailLogs
from dashboard.admin import DontLog

# Register your models here.
@admin.register(PushNotification)

class PushNotificationAdmin(DontLog, admin.ModelAdmin):
    search_fields = ['recipient__username', 'recipient__first_name', 'recipient__last_name', 'verb']
    pass

class EMailLogsAdmin(DontLog, admin.ModelAdmin):
    search_fields = ['sent_from__username','subject','content', 'application']
    fieldsets = [
    (None, {'fields': ['sent_from', 'sent_to', 'subject', 'content', 'application']}),
    ('Object Fields', {'fields': ['related_object_content_type', 'related_object_id']})
    ]
    autocomplete_fields=['sent_from', 'sent_to']

admin.site.register(EMailLogs, EMailLogsAdmin)

Is there anything else you need to help me fix this error?

I have tried upgrading and downgrading various versions of Django, notifications, django-notification-hq. I have searched ChatGPT, Bard, Stack Overflow, and other sites. At one point I tried putting in a PushNotifications class in notifications. It worked for a while but then started producing errors when other packages were upgraded.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
Debbie
  • 11
  • 2

0 Answers0