Skip to content

Instantly share code, notes, and snippets.

@JonnatasCabral
Created September 23, 2016 16:51
Show Gist options
  • Select an option

  • Save JonnatasCabral/2b69ab4e9bb6d5f23e10411c12ad84b3 to your computer and use it in GitHub Desktop.

Select an option

Save JonnatasCabral/2b69ab4e9bb6d5f23e10411c12ad84b3 to your computer and use it in GitHub Desktop.
from django import template
register = template.Library()
@register.inclusion_tag('templatetags/filters.html', takes_context=True)
def filter(context):
list_filters = []
dict_filters = []
for f in context['filters']:
if isinstance(f[1], tuple):
dict_filters.append(f)
else:
list_filters.append(f)
context.update({
'list_filters': list_filters,
'dict_filters': dict_filters,
})
return context
@register.filter(name='split')
def split(value):
return value.split('_')[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment