Skip to content

Commit

Permalink
Merge pull request #1399 from suecarmol/suecarmol/improve-admin
Browse files Browse the repository at this point in the history
Improve admin performance
  • Loading branch information
jsnshrmn authored Jan 3, 2025
2 parents afad426 + a77755b commit 0c0e34d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions TWLight/applications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ApplicationAdmin(VersionAdmin):
list_display = ("id", "partner", "editor")
list_filter = ("status", "partner")
raw_id_fields = ("editor", "sent_by", "parent", "partner")
list_select_related = ["partner", "sent_by", "editor"]

# reversion options
history_latest_first = True
Expand Down
11 changes: 8 additions & 3 deletions TWLight/resources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def language_strings(self, object):
class ContactAdmin(admin.ModelAdmin):
search_fields = ("partner__company_name", "full_name", "short_name")
list_display = ("id", "title", "full_name", "partner", "email")
list_select_related = ["partner"]


admin.site.register(Contact, ContactAdmin)
Expand All @@ -90,6 +91,7 @@ class ContactAdmin(admin.ModelAdmin):
class VideoAdmin(admin.ModelAdmin):
search_fields = ("partner__company_name", "tutorial_video_url")
list_display = ("partner", "tutorial_video_url", "id")
list_select_related = ["partner"]


admin.site.register(Video, VideoAdmin)
Expand All @@ -99,6 +101,7 @@ class AccessCodeAdmin(admin.ModelAdmin):
search_fields = ("code", "partner__company_name")
list_display = ("code", "partner", "authorization")
raw_id_fields = ("authorization",)
list_select_related = ["partner", "authorization"]

change_list_template = "accesscode_changelist.html"

Expand Down Expand Up @@ -193,9 +196,11 @@ def import_csv(self, request):

# Only upload this code if it doesn't already exist. If it does,
# increment a counter so we can report that.
access_code_partner_check = AccessCode.objects.filter(
code=access_code, partner=partner_pk
).count()
access_code_partner_check = (
AccessCode.objects.select_related("partner")
.filter(code=access_code, partner=partner_pk)
.count()
)
if access_code_partner_check != 0:
skipped_codes += 1
else:
Expand Down
1 change: 1 addition & 0 deletions TWLight/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class AuthorizationAdmin(admin.ModelAdmin):
"authorizer__editor__wp_username",
"user__editor__wp_username",
]
list_select_related = ["user", "authorizer", "authorizer__editor", "user__editor"]

form = AuthorizationAdminForm

Expand Down

0 comments on commit 0c0e34d

Please sign in to comment.