On Wed, May 4, 2011 at 11:42 AM, pankaj sharma <new.pankajsha...@gmail.com> wrote: > in template.. > > {% for college in list %} > {{college.city}} > {% endfor %} > > in views.py > > def list(request): > college_list=College.objects.all() > return render_to_response( > 'college/list.html', > {'list':college_list} > ) > > > > so suppose i have two colleges in one city so it is showing the city > name twice .. so how do i stop repetition..
two different solutions, depending on what do you want: A) if you only need the cities from a given college queryset, in the view do something like: render_to_response( 'college/list.html', {'cities_list':City.objects.filter(college_set__in = college_list)} ) B) if you want a list of colleges, separated by city, and only show the city once for each group of colleges: in the view: return render_to_response( 'college/list.html', {'list':college_list.order_by('city')} ) in the template: {% for college in list %} {% ifchanged %}{{college.city}}{% endifchanged %} {{college.name}} {% endfor %} -- Javier -- 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.