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

2👍

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

{% if A in X.Y.all %}
    Test
{% 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:

X.objects.filter(Y=A).exists()

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