FEAT(pg): sortable columns + date-range filters on the IPG+ admin panel
Make every PaymentRequest changelist column sortable ascending/descending (computed amount/user/jalali columns get an `ordering` so they sort by the underlying DB field; only the "check success again" action button stays unsortable). Add a default `-created_at` ordering and surface `updated_at` as its own sortable column. The created_at/updated_at DateTimeRangeFilters are retained and compose with sorting. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
7fccde4022
commit
fbe43a2cf4
1 changed files with 21 additions and 2 deletions
|
|
@ -72,12 +72,31 @@ def mark_as_registered(model_admin, request, queryset):
|
||||||
|
|
||||||
|
|
||||||
class PaymentRequestAdmin(admin.ModelAdmin):
|
class PaymentRequestAdmin(admin.ModelAdmin):
|
||||||
list_display = ['state', 'check_success_again', 'uuid', 'splited_amount', 'user_id', 'jajali_datetime',
|
list_display = ['state', 'check_success_again', 'uuid', 'amount_display', 'user_display', 'jalali_datetime_display',
|
||||||
'is_registered', 'created_at', 'application', 'gateway']
|
'is_registered', 'created_at', 'updated_at', 'application', 'gateway']
|
||||||
search_fields = ['application__uuid', 'application__client_id', 'amount', 'user__uuid']
|
search_fields = ['application__uuid', 'application__client_id', 'amount', 'user__uuid']
|
||||||
list_filter = ['application', 'state', 'gateway', ('created_at', DateTimeRangeFilter), ('updated_at', DateTimeRangeFilter)]
|
list_filter = ['application', 'state', 'gateway', ('created_at', DateTimeRangeFilter), ('updated_at', DateTimeRangeFilter)]
|
||||||
|
# Every real column in list_display can be sorted ascending/descending by
|
||||||
|
# clicking its header; the computed columns declare an `ordering` so they
|
||||||
|
# sort by the underlying DB field. Only the "check success again" action
|
||||||
|
# button stays unsortable.
|
||||||
|
sortable_by = ['state', 'uuid', 'amount_display', 'user_display', 'jalali_datetime_display',
|
||||||
|
'is_registered', 'created_at', 'updated_at', 'application', 'gateway']
|
||||||
|
ordering = ['-created_at']
|
||||||
actions = [export_exel, mark_as_registered]
|
actions = [export_exel, mark_as_registered]
|
||||||
|
|
||||||
|
@admin.display(description='Splited amount', ordering='amount')
|
||||||
|
def amount_display(self, obj):
|
||||||
|
return obj.splited_amount
|
||||||
|
|
||||||
|
@admin.display(description='User', ordering='user')
|
||||||
|
def user_display(self, obj):
|
||||||
|
return obj.user_id
|
||||||
|
|
||||||
|
@admin.display(description='Jajali datetime', ordering='created_at')
|
||||||
|
def jalali_datetime_display(self, obj):
|
||||||
|
return obj.jajali_datetime
|
||||||
|
|
||||||
def changelist_view(self, request, extra_context=None):
|
def changelist_view(self, request, extra_context=None):
|
||||||
extra_context = extra_context or {}
|
extra_context = extra_context or {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue