From 9049d8779cedf875d65f504f6f5c8831fdf253fd Mon Sep 17 00:00:00 2001 From: imperosol Date: Sat, 21 Jun 2025 15:06:08 +0200 Subject: [PATCH] improve counter admin pages --- counter/admin.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/counter/admin.py b/counter/admin.py index 10f04c8d..de1d9d0b 100644 --- a/counter/admin.py +++ b/counter/admin.py @@ -41,6 +41,7 @@ class ProductAdmin(SearchModelAdmin): "profit", "archived", ) + list_select_related = ("product_type",) search_fields = ("name", "code") @@ -81,20 +82,13 @@ class AccountDumpAdmin(admin.ModelAdmin): "customer", "warning_mail_sent_at", "warning_mail_error", - "dump_operation", + "dump_operation__date", "amount", ) + list_select_related = ("customer", "customer__user", "dump_operation") autocomplete_fields = ("customer", "dump_operation") list_filter = ("warning_mail_error",) - def get_queryset(self, request): - # the `amount` property requires to know the customer and the dump_operation - return ( - super() - .get_queryset(request) - .select_related("customer", "customer__user", "dump_operation") - ) - @admin.register(Counter) class CounterAdmin(admin.ModelAdmin): @@ -113,11 +107,14 @@ class RefillingAdmin(SearchModelAdmin): "customer__account_id", "counter__name", ) + list_filter = (("counter", admin.RelatedOnlyFieldListFilter),) + date_hierarchy = "date" @admin.register(Selling) class SellingAdmin(SearchModelAdmin): list_display = ("customer", "label", "unit_price", "quantity", "counter", "date") + list_select_related = ("customer", "customer__user", "counter") search_fields = ( "customer__user__username", "customer__user__first_name", @@ -126,6 +123,8 @@ class SellingAdmin(SearchModelAdmin): "counter__name", ) autocomplete_fields = ("customer", "seller") + list_filter = (("counter", admin.RelatedOnlyFieldListFilter),) + date_hierarchy = "date" @admin.register(Permanency)