good question ! 1) I like to use some optimization at view side not template 2) if i need something like your code I using optimization. Something like that :
{% with items = mymodels.items.all %} {% for item in items %} {{ item.name }} {% for tag in item.tags.all %} {{ tag }} {% endfor %} {% endfor %} {% endwith %} First records means get ALL record to the variable which should be cached and used sometimes later 3) Anyway i dont like "object.all " I like to retrieve minimum of the field for decreasing database loading Many thanks, Serge +380 636150445 skype: skhohlov On Fri, Aug 15, 2014 at 5:46 PM, Collin Anderson <cmawebs...@gmail.com> wrote: > you could try in your view: > > items = items.prefetch_related('tags') > > > -- > 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+unsubscr...@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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/0acd3536-93e7-463a-9805-06d1b9236b63%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/0acd3536-93e7-463a-9805-06d1b9236b63%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADTRxJPQ%2BRA2eOCw4WuYag238W_nxrEBQngVdUb-TgA7is_Tjw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.