On 16 July 2010 13:30, Luca Casagrande <[email protected]> wrote: > On Jul 16, 2:22 pm, Daniel Roseman <[email protected]> wrote: >> On Jul 16, 1:18 pm, Luca Casagrande <[email protected]> wrote: >> >> > Hello everybody, >> > is it possible to filter data inside template? I have 2 models with a >> > foreignkey relationship: >> >> > class Requests(models.Model): >> > name = models.CharField(max_length=16) >> > surname = models.CharField(max_length=16) >> >> > class Information(models.Model): >> > request = models.ForeignKey(Requests) >> > description = models.CharField(max_length=16) >> >> > From the view to the template I pass a dictionary of requests and one >> > of information. >> > What I need to do is something like this: >> >> > <table border='1'> >> > {% for r in requests %} >> > <tr> >> > {% for i in informations WHERE request=r %} >> > <td>{{i.description}}</td> >> > {% endfor %} >> > </tr> >> > {% endfor %} >> > </table> >> >> > Any idea? >> >> > Thx >> >> Use the backwards relationship: >> >> {% for i in request.information_set.all %} >> -- >> DR. > > Thx Daniel for answer. > In my example is {% for i in r.informations_set.all %} ? > > With informations the dictionary coming from the view. > > Thx
No. You don't need to send 'informations' from the view at all. You get each related set of 'information' objects directly from its corresponding 'request' object. Read this: http://docs.djangoproject.com/en/1.2/topics/db/queries/#following-relationships-backward -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

