display additional information, best practice

25 views
Skip to first unread message

Stefano Tranquillini

unread,
Oct 28, 2012, 2:08:56 PM10/28/12
to django...@googlegroups.com

Hi all.
just a question about how to proceed.
when i've to display data direct from the model (the db) one in a page is simple.
what if i want to display aggregate data or some data that needs logic?
i've to do it in the view and add the object to the contex, or it's better to do a custom tag filter?

what if i've a list of objects and for each object i've to compute an aggregate data?
for example i've a list of cars and for each car i want to know how many models exists. if i do in the view, how can i attach the aggregate data (which is a query) to each car? is it better to do with a custom tag filter?

ciao.

--
Stefano

Sergiy Khohlov

unread,
Oct 28, 2012, 5:02:56 PM10/28/12
to django...@googlegroups.com
Have you tried detailview ?
Also it is possible to add some values to the temple in view

2012/10/28 Stefano Tranquillini <stefano.tr...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Stefano Tranquillini

unread,
Oct 29, 2012, 7:13:20 AM10/29/12
to django...@googlegroups.com
i gave it a look. but seems that detail view let me to display a model by just writing the template and not the view. right?
the point is, i've information that are not already in the object i want to display.
example:
i want to display the model called "Question" which has a set of "answers" given by "users"
now, how can i display for each question:
- the number of answer
- the number of correct answer
- the set of users who correctly answered.
?

can i do this with the detailview? beacuse i didn't find it out. or do i've to create a class to match the data i want to display and render this in a template?
Reply all
Reply to author
Forward
0 new messages