[Answered ]-If x in <listOfModels.field> syntax


You’re pretty much there. You just have to return an actual queryset:

{% if A in X.Y.all %}
{% endif %}

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.

Leave a comment