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 mailtemplate admin page performance #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions dbmail/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ def get_prepopulated_fields(self, request, obj=None):
return super(MailTemplateAdmin, self).get_prepopulated_fields(
request, obj)

def get_queryset(self, request):
return super(MailTemplateAdmin, self).get_queryset(request) \
.select_related('from_email', 'category')

def formfield_for_foreignkey(self, db_field, request, **kwargs):
formfield = super(MailTemplateAdmin, self).formfield_for_foreignkey(
db_field, request, **kwargs)
if db_field.name == 'category':
key = '_category_choices_cache'
if not hasattr(request, key):
setattr(request, key, list(formfield.choices))
formfield.choices = getattr(request, key)
return formfield


class MailLogEmailInline(admin.TabularInline):
readonly_fields = [field.name for field in MailLogEmail._meta.fields]
Expand Down