Skip to content

Instantly share code, notes, and snippets.

@mintchaos
Forked from blturner/gist:249882
Created December 5, 2009 22:20
Show Gist options
  • Save mintchaos/249886 to your computer and use it in GitHub Desktop.
Save mintchaos/249886 to your computer and use it in GitHub Desktop.
@register.filter
def exclude_fields(form, field_names):
"""
Returns the fields of a Form excluding the named fields. Usage:
{% for field in form|exclude_fields:"field1,field2,field3" %}
"""
fields = []
if isinstance(form, BaseForm):
field_names = field_names.split(',')
for field in form.fields:
if field not in field_names:
fields.append(BoundField(form, form.fields[field], field))
return fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment