From 8a1fcda9a1a7a1e2b5708aadbe83a8b09898dcda Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Wed, 28 Jun 2017 19:25:18 -0600 Subject: [PATCH] Better search, filtering, and display. --- bikeshop_project/core/admin.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bikeshop_project/core/admin.py b/bikeshop_project/core/admin.py index d4610b4..a7ee821 100644 --- a/bikeshop_project/core/admin.py +++ b/bikeshop_project/core/admin.py @@ -7,5 +7,17 @@ admin.site.register([Membership, Payment]) @admin.register(Visit) class VisitAdmin(admin.ModelAdmin): + list_select_related = ('member',) + fields = ('member', 'purpose', 'created_at') ordering = ('created_at',) - list_display = ('member', 'purpose', 'created_at') + list_display = ('full_name', 'purpose', 'created_at') + list_filter = ( + ('purpose', admin.ChoicesFieldListFilter), + ) + + search_fields = ['member__email', 'member__last_name', 'member__first_name'] + + def full_name(self, obj): + return obj.member.full_name + + full_name.admin_order_field = 'member__last_name'