Hi dimitri
Well, I am not sure this is a good suggestion but the way to get around any template code would be to do it in the query. Have you tried something like this: your_list = [] # i don't know how to initialise an empty query set authors = Author.objects.order_by('name') for author in authors: books = Book.objects.filter(author__name__exact=author.name) your_list.append(author) for book in books: your_list.append(book) But this is not so good I think. nausikaa On Sep 24, 9:49 am, dimitri pater - serpia <dimitri.pa...@gmail.com> wrote: > Hi, > > say, I have two related models: > > class Author(models.Model): > name = models.CharField() > > class Book(models.Model): > author = models.ForeignKey(Author) > titel = models.CharField() > isbn = models.CharField() > > and I want to group them and display them in a template like this: > > Stephen King: > ========== > Green Mile 7878787 > Four past midnight 909090 > etc.. > > Daphne du Maurier: > ========== > Rebecca 565656 > Don't look now 232323 > etc.... > > what is the best way to this (in the view, maybe using 'grop_by'), > without having to write too much template code? > Your suggestions are welcome, thank! > > dimitri --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---