Monday, May 13, 2013

Adding a summary column in a view

I am currently working on a site where there are several models which do not have immediate views, but rather are attached to other models via foreign keys. I need to prepare a view in which the data of these models (or rather, their underlying tables) are summed and presented in several columns. I have partially written the views so as to gather the data into a nested set of dictionaries, but since templates do not have any support for dictionaries (to the best that I know, anyway), this is obviously only part of the solution. Can anyone offer an approach that would allow me to populate a dynamically generated Model subclass object with the computed sums and pass it to the template?

I have done some reading on this, and have seen references to custom template aggregation filters. Would something of this nature solve the problem?

In addition to this, I will also need to prepare a ratio of two separate fields, again in several columns and shown as a percentage. Is it possible to write a filter that aggregates in this manner?

Let me know if any further information is needed, or if I should post the existing (incomplete) code.

(Note: An earlier version of this was originally posted to http://djangoforum.com today; I would not normally cross-post something like this, except that the traffic there is so light I am concerned that I will not get an answer in a timely fashion. In retrospect, I should have come here first, but what's done is done.)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate