#24541: save_new_objects in ModelFromsets do not handle intitial data
-------------------------------+--------------------------------------
Reporter: codingjoe | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: modelformset | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by codingjoe):
As I said:
It does not work if your objects are not yet created and you can't pass a
queryset.
{{{
from django.forms.models import modelformset_factory
def test_view(request):
qs = Poll.objects.none()
PollFormSet = modelformset_factory(Poll, fields='__all__')
if request.method == 'POST':
formset = PollFormSet(request.POST, inital=[{'vote': 2},
{'vote':4}])
if formset.is_valid():
obj_list = formset.save()
assert len(obj_list) == 2
else:
formset = PollFormSet(queryset=qs, initial=[
{'question': 'initial', 'pub_date': timezone.now()}])
return render(request, 'polls/manage.html', {'formset': formset})
}}}
This will fail.
--
Ticket URL: <https://code.djangoproject.com/ticket/24541#comment:4>
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/067.6009d4221055e81824b78542d3594781%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.