Modelform documentation on editing an existing object needs to be updated.
|Reported by:||Eric Holscher||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In the documentation in the section: the save method:
It is unclear that when you are creating a modelform of POSTed object, the correct syntax is:
article = Article.objects.get(pk=id) new = ModelForm(request.POST, article) new.save()
for when you are trying to update an object, instead of create a new one.
The code section:
# Create a form instance with POST data. >>> a = Author() >>> f = AuthorForm(request.POST, instance=a) # Create and save the new author instance. There's no need to do anything else. >>> new_author = f.save()
is the second example of creating a form with POST data, and should instead show how to update a form with POST data.
Change History (5)
comment:1 Changed 9 years ago by
|Component:||django.newforms → Documentation|
|Patch needs improvement:||unset|
comment:3 Changed 8 years ago by
|Triage Stage:||Unreviewed → Ready for checkin|