sum in admin list view
This commit is contained in:
parent
92849481d1
commit
9462e25de2
2 changed files with 24 additions and 0 deletions
|
|
@ -1,4 +1,6 @@
|
|||
from django.contrib import admin
|
||||
from django.db.models import Sum
|
||||
|
||||
from .models import PaymentRequest, PNA, Fake
|
||||
|
||||
|
||||
|
|
@ -13,6 +15,17 @@ class PaymentRequestAdmin(admin.ModelAdmin):
|
|||
search_fields = ['application__uuid','application__client_id', 'amount', 'user__uuid']
|
||||
list_filter = ['application', 'state', 'gateway']
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
extra_context = extra_context or {}
|
||||
|
||||
cl = self.get_changelist_instance(request)
|
||||
queryset = cl.result_list
|
||||
totals = queryset.aggregate(
|
||||
total_amount=Sum('amount'),
|
||||
)
|
||||
extra_context['totals'] = totals
|
||||
return super().changelist_view(request, extra_context=extra_context)
|
||||
|
||||
|
||||
class FakeAdmin(admin.ModelAdmin):
|
||||
list_display = [ 'created_at']
|
||||
|
|
|
|||
11
templates/admin/pg/paymentrequest/change_list.html
Normal file
11
templates/admin/pg/paymentrequest/change_list.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{% extends "admin/change_list.html" %}
|
||||
{% load tags %}
|
||||
{% block result_list %}
|
||||
{{ block.super }}
|
||||
<div style="margin-top: 20px; padding: 10px; background: #f8f8f8;">
|
||||
<h3>جمع کل:</h3>
|
||||
<p></p>
|
||||
<p>{{ totals.total_amount|default:"0"|amount_split_3digit }}</p>
|
||||
<p></p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Reference in a new issue