mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-03-16 21:30:24 +00:00
Added prefetch for actor field in admin
This commit is contained in:
parent
bf772f6d44
commit
afef4a251b
2 changed files with 32 additions and 0 deletions
|
|
@ -10,5 +10,9 @@ class NotificationAdmin(admin.ModelAdmin):
|
|||
'level', 'target', 'unread', 'public')
|
||||
list_filter = ('level', 'unread', 'public', 'timestamp',)
|
||||
|
||||
def get_queryset(self, request):
|
||||
qs = super(NotificationAdmin, self).get_queryset(request)
|
||||
return qs.prefetch_related('actor')
|
||||
|
||||
|
||||
admin.site.register(Notification, NotificationAdmin)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ import pytz
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import connection
|
||||
from django.template import Context, Template
|
||||
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
|
||||
|
|
@ -510,3 +512,29 @@ class TagTest(TestCase):
|
|||
context = {"user":self.to_user}
|
||||
output = u"True"
|
||||
self.tag_test(template, context, output)
|
||||
|
||||
|
||||
class AdminTest(TestCase):
|
||||
def setUp(self):
|
||||
self.message_count = 10
|
||||
self.from_user = User.objects.create_user(username="from", password="pwd", email="example@example.com")
|
||||
self.to_user = User.objects.create_user(username="to", password="pwd", email="example@example.com")
|
||||
self.to_user.is_staff = True
|
||||
self.to_user.is_superuser = True
|
||||
self.to_user.save()
|
||||
for _ in range(self.message_count):
|
||||
notify.send(
|
||||
self.from_user,
|
||||
recipient=self.to_user,
|
||||
verb='commented',
|
||||
action_object=self.from_user,
|
||||
)
|
||||
|
||||
def test_list(self):
|
||||
self.client.login(username='to', password='pwd')
|
||||
|
||||
with CaptureQueriesContext(connection=connection) as context:
|
||||
response = self.client.get(reverse('admin:notifications_notification_changelist'))
|
||||
self.assertLessEqual(len(context), 6)
|
||||
|
||||
self.assertEqual(response.status_code, 200, response.content)
|
||||
|
|
|
|||
Loading…
Reference in a new issue