Check for exact presence in a queryset django, jinja 2

in my case, I have a question to check if the exact string name of a model does exist in a query set. here is my code:

if Despiking.objects.filter(user=request.user).exists():
    filtered_projects = Despiking.objects.filter(user=request.user)
        'filtered_projects': filtered_projects.__str__(),


{% if info.project_name in filtered_projects %}
    <!-- some HTML elements -->
{% else %}
    <!-- other HTML elements -->
{% endif %}

in my code, there is no difference between "my project" and "project" as info.project_name model. because of that the "project" word exists in the query set when I have only the "my project" in it. so using {% if info.project_name in filtered_projects %} works the same (the condition of if will be True) because that "project" word exists in the query set because of the "my project". what can I do to check the exact string in it?

You can use __exact or __iexact for exact matching in case-sensitive and case-insensitive operations respectively.

Share your Despiking model, I'd edit the answer.

Back to Top