Skip to content

Instantly share code, notes, and snippets.

@vitorfs
Created August 4, 2016 09:59
Show Gist options
  • Save vitorfs/d361f88fd05e9800bd272c004961e790 to your computer and use it in GitHub Desktop.
Save vitorfs/d361f88fd05e9800bd272c004961e790 to your computer and use it in GitHub Desktop.
Django Field Type Filter
{% load fieldtype %}
{% for field in form.visible_fields %}
{% if field|fieldtype == 'CheckboxInput' %}
...
{% elif field|fieldtype == 'CheckboxSelectMultiple' %}
...
{% endif %}
...
{% endfor %}
from django import template
register = template.Library()
@register.filter('fieldtype')
def fieldtype(field):
return field.field.widget.__class__.__name__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment