Code

Opened 6 years ago

Closed 6 years ago

#6891 closed (fixed)

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

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

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 programmerq 6 years ago.
worked up a patch

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by ericholscher

  • Component changed from django.newforms to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by ericholscher

  • Needs documentation set

Changed 6 years ago by programmerq

worked up a patch

comment:3 Changed 6 years ago by programmerq

  • Has patch set
  • Needs documentation unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.