FEAT(pg): sortable columns + date-range filters on the IPG+ admin panel #7

Merged
Ghasemi merged 1 commit from feature/ipg-panel-filter-sort into master 2026-09-06 09:58:37 -04:00

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 {}