Hi, I am running into an annoying problem when trying to create formsets dynamically.
I have a script that sends JSON data to a view to render it as a formset. The response is then inserted in the page: Script: data = JSON.stringify([1, 2, 3]); $("#container").load("render-form/", {data: data}); View: def render_form(request): data = simplejson.loads(request.POST["data"]) objs = [SomeModel(i) for i in data] FormSet = modelformset_factory(SomeModel, extra=0) forms = FormSet(queryset=objs) return render_to_response("form_template.html", {"forms": forms}) It works but I get incorrect ManagementForm data in the output: <input id="id_somemodel-TOTAL_FORMS" type="hidden" value="3" name="attendee-TOTAL_FORMS"/> <input id="id_somemodel-INITIAL_FORMS" type="hidden" value="3" name="attendee-TOTAL_FORMS"/> For django to save the formset correctly when it is submitted, I have to manually set INITIAL_FORMS to 0 in javascript (because the objects are not really in the database). I tried to create the formset using extra=3 and passing the data via the 'initial' argument, but this gives an IndexError (django is trying to set the forms 'instance' attribute from the queryset, but it is empty). Is there a less hackish way to do this ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---