I want to access context in filter:
NOT working example (showing what I want to get)
{% for phone in person.communicator_set.all|phones %}
{{ phone.number }}
{% endfor %}
templatetags/filters.py
@register.filter(takes_context=True)
def context_filter(context,queryset):
return queryset.filter(validity_range__contains=context['context_date'])
But this doesn't work...
Updated code as per comments discussion.
Update your filter function with the code given below:
After this in your template file you can call the custom filter as below: