You can use templatetags for example: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs
On Saturday, April 14, 2012 10:51:51 AM UTC+2, Nikhil Somaru wrote: > > Greetings, > > > I would like to do something like queryset filtering in a template. Is the > only solution via a template tag? > > > # models.py > > class StudentProfile(models.Model): > > # class defined here > > # ... > > > class Department(models.Model): > > # ... > > students = models.ManyToManyField('StudentProfile', null=True, blank=True) > > # ... > > > class Activity (models.Model): > > # ... > > department = models.ForeignKey('Department') > # ... > > I would like to do the following in a template: > > The context variable is student > > {% for dept in student.department_set.all %} > * *{% for activity in student.activity_set.all.* > filter(department=dept)* %} > {{ activity }} > {% endfor %} > {% endfor %} > > This would produce something like a list of all activities for each > department the student is in. I have removed formatting and html to make it > clearer. > > Obviously, you can't pass arguments to filter in a template. How can one > achieve this? > > -- > Yours, > Nikhil Somaru > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xCxO0M5DP7AJ. 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.