Wednesday, March 27, 2013

No multiple calls while iterating the queryset in template

Interesting Observation: So, am passing a queryset to my template and based on the way a field in the record 'starts-with', i am rendering the record into different 'tables' in the view.

Something like:

{% for record in settings %}
 {%if record.type|starts_with:"EMAIL_" %}
    <tr> ...show record details .. </tr>
 {% endif %}
{% endfor %}


{% for record in settings %}
 {%if record.type|starts_with:"WORKSPACE_" %}
    <tr> ...show record details .. </tr>
 {% endif %}
{% endfor %}


{% for record in settings %}
 {%if record.type|starts_with:"DASHBOARD_" %}
    <tr> ...show record details .. </tr>
 {% endif %}
{% endfor %}

I was worried that passing over the queryset in different regions in the 'same' template might cause multiple(in this case 3) different queries to the DB. But DDT shows me just one query to the DB :)

Regards,
Venkat
@venkasub

--
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.
 
 

No comments:

Post a Comment