Skip to content

Instantly share code, notes, and snippets.

@blturner
Created December 5, 2009 22:10
Show Gist options
  • Save blturner/249882 to your computer and use it in GitHub Desktop.
Save blturner/249882 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 not isinstance(form, BaseForm):
return fields
else:
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