Tuesday, January 26, 2016

Re: count



On Tue, Jan 26, 2016 at 6:12 AM, Andreas Schosser <a@kurs-10.de> wrote:
Hi

> i am trying to count the number of fields that has request field begin
> checked and then display the value of count in a template.html but i am not
> sure how to go about doing that.

If you pass your object to the template you can use the "length" filter:

{{ test|length }}

I would only do this if {{ test }} contains objects that you actually want to process/display elsewhere in the template. If you only need the count, I would recommend sticking with the .count() query and passing it through the context since that is faster and more efficient to process, especially for items like votes or likes, where the numbers may reach into the thousands or more.

-James

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWmp%3Du297mUxO5qMfAvkbYGc9sS8hDQ8fuw4cgcJ_n5dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment