I have a model Data, associated to a table like this (The model Data is made up of only IntegerField):
subject | year | quarter | sales |
----------------------------------
1 | 2010 | 1 | 20 |
1 | 2010 | 2 | 100 |
1 | 2010 | 3 | 100 |
1 | 2010 | 4 | 20 |
1 | 2011 | 1 | 30 |
1 | 2011 | 2 | 50 |
1 | 2011 | 4 | 40 |
2 | 2010 | 1 | 30 |
2 | 2010 | 2 | 20 |
[..-GO ON this way...]
I want to have a django-admin table, in read-only having columns (current year = 2011, quarter = 1)
subject | sales current year | sales current quarter | sales last year | sales current quarter last year |
----------------------------------------------------------------------------------------------------------
1 | 110 | 30 | 240 | 20
[AND SO ON]
The question is: It is possible do that using django-admin? What’s the way out?
You can use methods on your
Modelor yourModelAdminas items forlist_display. See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_displaySince these are methods that might be useful outside the admin, as well, I’d suggest adding them to your
Model.The
short_descriptionattribute determines what the admin will show as the row header for these methods. So, once you have all this in place, you need only modify yourModelAdmin‘slist_displayattribute like: