Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of MessageAdmin #286

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion django_mailbox/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from django.conf import settings
from django.contrib import admin
from django.db.models import Count
from django.utils.translation import gettext_lazy as _

from django_mailbox.models import MessageAttachment, Message, Mailbox
Expand Down Expand Up @@ -60,8 +61,11 @@ class MessageAttachmentInline(admin.TabularInline):


class MessageAdmin(admin.ModelAdmin):
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).annotate(num_attachments=Count('attachements'))

def attachment_count(self, msg):
return msg.attachments.count()
return msg.num_attachments

attachment_count.short_description = _('Attachment count')

Expand Down
Loading