How to add more information (like count, sum(same date)) at bottom

like to add statistics infomation ,but how to do

  • Calculate that information in your view

  • Include the results of the calculations in the context

  • Display those elements in your template.

thank for your reply。
yes, i usually do what you said . (render result in my html template)
this time , i use django admin site to show result (is so simple), but how to add statistics information make me confuse

You might be able to do what you want by overriding the ModelAdmin.changelist_view and/or the ModelAdmin.change_list_template for those models.

One aspect of this you’ll want to consider is how pagination will affect this. Do you want your totals to reflect the entire table or just the list of entries on that particular page? (That’s a decision you’ll need to make, and it may affect your code accordingly.)

But, in my opinion, you’re quickly approaching the point where you’re going beyond what the admin is designed to do. You may actually find it easier to code your own view with this data than to try to wedge your functionality into the admin. (This is especially true if you’re going to expose this to non-admin personnel. I always strongly recommend against exposing the admin as any part of your user-facing UI.)

1、I get you point~~ is very helpful. So I 'll try to overriding ModelAdmin.changelist_view /template

2、About pagination . As an administrator, they only care about the total of qualified data, not whether there are paging . -----thank for your remind

3、I only show admin to adminstrotor not user.

My idea is to provide administrators with intuitive statistics, not just lists, So i 'll try~~~

thanks a lot

1 Like