handling formsets

This commit is contained in:
Mauro Bianchi
2012-07-04 10:51:29 +02:00
parent a307fce656
commit 6ba3f27868
2 changed files with 14 additions and 2 deletions

View File

@@ -7,12 +7,19 @@ register = template.Library()
@register.filter
def bootstrap(element):
element_type = element.__class__.__name__.lower()
if element_type == 'boundfield':
template = get_template("bootstrapform/field.html")
context = Context({'field': element})
else:
template = get_template("bootstrapform/form.html")
context = Context({'form': element})
has_management = getattr(element, 'management_form', None)
print "has management", has_management
if has_management:
template = get_template("bootstrapform/formset.html")
context = Context({'formset': element})
else:
template = get_template("bootstrapform/form.html")
context = Context({'form': element})
return template.render(context)

View File

@@ -0,0 +1,5 @@
{{ formset.management_form }}
{% for form in formset %}
{% include "bootstrapform/form.html" with form=form %}
{% endfor %}