The easiest way is probably moving that list to the view. For example customers = Customer.objects... sellers = Seller.objects...
filtered_list = [pair for pair in zip(sellers, customers) if pair[0].customer_id == pair[1].id] Then pass filtered_list into the template context. Inside the template, you could do: (Assuming Django >= 1.1) {% for seller, customer in filtered_list %} <p>{{ seller.name }} {{ customer.name }} </p> {% empty %} <p>No customers.</p> {% endfor %} -- dz On Wed, Aug 12, 2009 at 5:06 AM, elminio<wgruszczyn...@gmail.com> wrote: > > Hello, > > Common task in template is doing for loop end inserting into html some > elements. > > for example > > 1: {% for seller in sellers %} > 2: {% for customer in customers %} > 3: {% ifequal seller.customer_id customer.id %} > 4: <p>{{ seller.name }} {{ customer.name }} </p> > 5: {% endifequal %} > 6: {% endfor %} > 7: {% endfor %} > > > Thats clear. > > Now I would like to know when the loop is over and system didnt't find > customer for seller (line 3). And in this case insert <p>no customers</ > p>. > > If it shouldnt be done in template how can I inject logic from python > file ? > > thanks for help > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---