[Django]-Is it possible for a Django template to test for existence of a row in a table without writing a custom tag/filter?

5👍

Template filters are not big guns:

# your_app/templatetags/following.py 

from django import template
register = template.Library()

@register.filter
def is_followed_by(post, user):
   return post.is_followed_by(user)  

and then:

{% load following %}
...
{% if post|is_followed_by:user %} ... {% endif %}

You can also put all logic in template filter, remove ‘post.is_followed_by’ method and use the filter instead of model method just like any other function, @register.filter decorator doesn’t harm the decorated function.

Leave a comment