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
This commit is contained in:
commit
951a1a6a06
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):
|
||||
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 {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue