do the filtering part in views.py . templates is meant only for visual
purpose

On Sat, Apr 14, 2012 at 2:21 PM, Nikhil Somaru <nsom...@gmail.com> 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 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.
>

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

Reply via email to