diff --git a/rentals/admin.py b/rentals/admin.py index 5fed375..9fd1568 100644 --- a/rentals/admin.py +++ b/rentals/admin.py @@ -1,6 +1,8 @@ +from django.db.models import Prefetch from django.contrib import admin from django import forms +from membershipworks.models import Member from .models import LockerBank, LockerInfo, LockerUnit @@ -28,7 +30,7 @@ class LockerUnitAdmin(admin.ModelAdmin): @admin.register(LockerInfo) class LockerInfoAdmin(admin.ModelAdmin): search_fields = ["renter__username", "locker_unit__bank__name"] - list_filter = ["locker_unit__bank", "locker_unit", "renter"] + list_filter = ["locker_unit__bank", "locker_unit"] list_display = [ "locker_unit", "address", @@ -41,7 +43,11 @@ class LockerInfoAdmin(admin.ModelAdmin): list_editable = ["blind_code", "bitting_code"] def get_queryset(self, request): - return LockerInfo.objects.select_related("locker_unit", "locker_unit__bank") + return LockerInfo.objects.select_related( + "locker_unit", "locker_unit__bank" + ).prefetch_related( + Prefetch("renter", queryset=Member.objects.only("account_name")) + ) def get_changelist_formset(self, request, **kwargs): kwargs["widgets"] = {