Reputation: 1015
As far as I'm aware, even as of Django 1.5, there's no built-in handling of nested formsets - i.e. I have an arbitrary number of groups, to which I must add an arbitrary number of members, all from the same page. I'm currently trying to use Nathan Yergler's method to do so, but it seems to be broken under Django 1.5.
The gist of the method is to override the group formset's add_fields
method to include an inline_formset
of members. However, when I create a GroupFormSet instance in the view, regardless of whether I've passed any group instances, I get a ValidationError: 'ManagementForm data is missing or has been tampered with'
For example, a snippet from my view's get_context_data
:
group_inst = models.TemplateFieldGroup.objects.filter(name="Study")[0]
context['group_formset'] = forms.GroupFormSet(instance=group_inst)
Has anyone successfully deployed this method under Django 1.5, or perhaps does anyone have a better way to accomplish the same goal?
Slight edit: my 'groups' are actually members of an even larger umbrella: a Template object has multiple TemplateFieldGroups which have multiple TemplateFields. However, even passing GroupFormSet() a proper Template instance doesn't solve the issue at hand.
Upvotes: 1
Views: 677
Reputation: 1015
So the final solution to my problem, and unfortunately I can't say I fully understand it, can be found here on Andrei Petre's (old) blog. http://andreipetre.tumblr.com/post/26203496689/nested-formsets-with-django
Upvotes: 0
Reputation: 11
I had a similar issue recently. I solved it by creating some custom form and formset classes based on the StackOverflow answer from: Django admin - inline inlines (or, three model editing at once)
This method worked well for Django 1.4 but stopped working when I updated to Django 1.5. To solve it I created a github repository: https://github.com/didorothy/mlrma
The README.md explains my specific situation and goals more fully. My solution is focused on the Django admin but could be pieced apart and used alone. To do more than three levels it could be extended.
Upvotes: 1