I have a model X with a ManyToMany field Y, my query returns a list of X’s,
How do I do something like:
{% if A in X.Y %}
Test
{% endif %}
EDIT: X is still a querySet (I’m not iterating the set).
Thanks in advance,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re pretty much there. You just have to return an actual queryset:
UPDATE (based on comment)
That is not possible with template code, you need to do a filter, and the Django templating language doesn’t allow passing parameters to methods. In your view, you can do:
And pass the result into the context to be used in the template, but I’m not sure how that fits with your exact needs.