On Feb 21, 11:14 am, Jeremy Dillworth <jdillwo...@gmail.com> wrote: > and a view named list: > > def list(request): > people = Person.objects.all() > for p in people: > p.columns = [None, None, None] > for c in DataPoint.objects.filter(person=p, value__gt=4): > p.columns.append(c) > > return render_to_response('people/listing.html', > dict(people=people))
I should probably mention too that the view code in my example may be a bit unwise. I just wanted to keep it simple. For real production code, I would wonder if doing a query in a loop like that would scale. Potentially this view could do dozens of queries during a single HTTP request. A better option would be to do one hit on the DataPoint table that pulls all the DataPoints for all the Person objects, then use some dictionaries and lists to get them into their proper places. Or you could even just do select_related on the DataPoints and get the Person objects at the same time... Jeremy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.