Adding a "subtotal" row to the Admin change list page?

742 views
Skip to first unread message

Eric

unread,
Nov 11, 2008, 9:39:48 PM11/11/08
to Django users
Hi folks, I am using the default Admin pages for my site, and I have a
modification/customization question.

I am wondering what the best approach would be to modify the admin
change list page so that there can be a new row that sums the contents
of all the other rows. For example, each row in the change list page
contains a used car transaction, and I want a row that totals up the
value of all the used cars in the list. I would also like this total
to be consistent with any filters that may be applied (for example,
the car's make/model).

I'm relatively new to Django, so I thought someone here might be able
to help. I've searched around and have tried a few things but haven't
had much luck yet. Thanks much for the guidance.


Ronny Haryanto

unread,
Nov 12, 2008, 1:35:59 AM11/12/08
to django...@googlegroups.com
On Wed, Nov 12, 2008 at 9:39 AM, Eric <Eric.S...@gmail.com> wrote:
> Hi folks, I am using the default Admin pages for my site, and I have a
> modification/customization question.
>
> I am wondering what the best approach would be to modify the admin
> change list page so that there can be a new row that sums the contents
> of all the other rows. For example, each row in the change list page
> contains a used car transaction, and I want a row that totals up the
> value of all the used cars in the list. I would also like this total
> to be consistent with any filters that may be applied (for example,
> the car's make/model).

You can modify the admin templates, particularly the change list
template (change_list.html), to *show* the subtotal. See here for more
info re: modifying the admin templates:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

*Obtaining* the subtotal is another issue. One way is to use
Javascript that is (conditionally) loaded from the template. There are
other possibilities: custom model manager method, custom SQL that
includes SUM(...) as a field, and maybe custom ModelAdmin (I'm not too
sure about this though). Once you get the subtotal you can display it
using custom admin template.

Hope that gives you a starting point.

Ronny

Reply all
Reply to author
Forward
0 new messages