#21955: Formset save_as_new=True causes "This QueryDict instance is immutable"
error
----------------------------+--------------------
     Reporter:  robin       |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.6
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 Basically if you post a properly setup inline formset with
 '''save_as_new=True''' argument:
 {{{
 FormSet = inlineformset_factory(Model, SubModel)
 formset = FormSet(request.POST, save_as_new=True)
 }}}
 You will get
 {{{
 AttributeError at /
 This QueryDict instance is immutable
 }}}

 '''Some demo code below:'''

 views.py
 {{{#!python
 from django.forms.models import inlineformset_factory
 from django.middleware.csrf import get_token
 from django.http import HttpResponse
 from django.template.base import Template, Context

 from app.models import App, SubApp

 def home(request):
     FormSet = inlineformset_factory(App, SubApp)
     if request.method == 'POST':
         formset = FormSet(request.POST, save_as_new=True)
     else:
         formset = FormSet()

     csrf = get_token(request)

     t = '''
         <form method="POST">
             {{ formset }}
             <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf
 }}" />
             <input type="submit" />
         </form>
     '''
     c = {
         'formset': formset,
         'csrf': csrf,
     }
     s = Template(t).render(Context(c))
     return HttpResponse(s)
 }}}

 models.py
 {{{#!python
 from django.db import models

 class App(models.Model):
     pass

 class SubApp(models.Model):
     app = models.ForeignKey(App)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21955>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.f3ee82cdb10b145315f56ba9e5515603%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to