Skip to content

Commit

Permalink
admin: Generally sort gate by time descending
Browse files Browse the repository at this point in the history
Usually we want the most recent activity, so this will often be a more
useful sort order.
  • Loading branch information
dehnert committed Feb 20, 2025
1 parent f92c704 commit a2649ad
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions squaresdb/gate/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
class Admin_SubscriptionPeriod(VersionAdmin):
fields = ['slug', 'name', 'start_date', 'end_date', ]
list_display = fields
ordering = ['start_date']
ordering = ['-start_date']


@admin.register(gate_models.SubscriptionPeriodPrice)
class Admin_SubscriptionPeriodPrice(VersionAdmin):
list_display = ['period', 'fee_cat', 'low', 'high']
list_filter = ['period', 'fee_cat']
ordering = ['period', 'low']
ordering = ['-period', 'low']


@admin.register(gate_models.DancePrice)
Expand All @@ -46,6 +46,7 @@ class Admin_DancePriceScheme(VersionAdmin):
class Admin_Dance(VersionAdmin):
list_display = ['time', 'period', 'price_scheme']
list_filter = ['period', 'price_scheme']
ordering = ['-time', ]
date_hierarchy = 'time'


Expand All @@ -69,15 +70,21 @@ def mail_merge(modeladmin, request, queryset):

@admin.register(gate_models.SubscriptionPayment)
class Admin_SubscriptionPayment(VersionAdmin):
# In an ideal world, we'd show the periods in the list, but ManyToManyField
# isn't supported in list_display.
actions = [mail_merge]

list_display = ['time', 'person', 'at_dance', 'payment_type', 'get_periods']
ordering = ['at_dance', 'person']
list_filter = ['periods', 'payment_type']
search_fields = ['person__name', 'person__email']
date_hierarchy = 'time'

# I think ideally we maybe want something like "order by the dance time,
# but if there's no dance, use the payment time instead" (so that payments
# at the door appear together sorted by name, but new credit card payments
# are also early), but I'm not sure that's possible and this is like 99% as
# good -- it just means the sort is strictly time-based, rather than being
# partially alphabetical.
ordering = ['-time', '-at_dance', 'person']

def get_queryset(self, request):
# Based on https://stackoverflow.com/a/67639818/1797496
qs = super().get_queryset(request)
Expand All @@ -92,7 +99,7 @@ def get_periods(self, obj):
class Admin_DancePayment(VersionAdmin):
actions = [mail_merge]
list_display = ['time', 'for_dance', 'person', 'at_dance', 'payment_type', ]
ordering = ['for_dance', 'person']
ordering = ['-for_dance__time', 'person']
list_filter = ['for_dance__period', 'payment_type']
search_fields = ['person__name', 'person__email']
date_hierarchy = 'for_dance__time'
Expand All @@ -105,3 +112,4 @@ class Admin_Attendee(VersionAdmin):
list_display = fields
search_fields = ['person__name', 'person__email']
date_hierarchy = 'dance__time'
ordering = ['-dance__time', 'person']

0 comments on commit a2649ad

Please # to comment.