Opened 16 years ago

Closed 16 years ago

#6891 closed (fixed)

Modelform documentation on editing an existing object needs to be updated.

Reported by: Eric Holscher Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the documentation in the section: the save method:
http://www.djangoproject.com/documentation/modelforms/#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.

Attachments (1)

6891.diff (591 bytes ) - added by Jeff Anderson 16 years ago.
worked up a patch

Download all attachments as: .zip

Change History (5)

comment:1 by Eric Holscher, 16 years ago

Component: django.newformsDocumentation

comment:2 by Eric Holscher, 16 years ago

Needs documentation: set

by Jeff Anderson, 16 years ago

Attachment: 6891.diff added

worked up a patch

comment:3 by Jeff Anderson, 16 years ago

Has patch: set
Needs documentation: unset
Triage Stage: UnreviewedReady for checkin

comment:4 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(In [7728]) Fixed #6891 -- Clarified modelform usage documentation. Thanks to Eric Holscher for the suggestion.

Note: See TracTickets for help on using tickets.
Back to Top