Compare commits

..

2 commits

Author SHA1 Message Date
951a1a6a06 Merge pull request 'FEAT(pg): sortable columns + date-range filters on the IPG+ admin panel' (#7) from feature/ipg-panel-filter-sort into master
Reviewed-on: #7
2026-09-06 09:58:36 -04:00
fbe43a2cf4 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>
2026-09-06 13:24:50 +03:30

View file

@ -72,12 +72,31 @@ def mark_as_registered(model_admin, request, queryset):
class PaymentRequestAdmin(admin.ModelAdmin):
list_display = ['state', 'check_success_again', 'uuid', 'splited_amount', 'user_id', 'jajali_datetime',
'is_registered', 'created_at', 'application', 'gateway']
list_display = ['state', 'check_success_again', 'uuid', 'amount_display', 'user_display', 'jalali_datetime_display',
'is_registered', 'created_at', 'updated_at', 'application', 'gateway']
search_fields = ['application__uuid', 'application__client_id', 'amount', 'user__uuid']
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]
@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):
extra_context = extra_context or {}