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.
--
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.