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.
Source:stackexchange.com