Django

Code

Ticket #6891 (closed: fixed)

Opened 5 months ago

Last modified 3 months ago

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

Reported by: ericholscher Assigned to: nobody
Milestone: Component: Documentation
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

6891.diff (0.6 kB) - added by programmerq on 06/11/08 21:08:50.
worked up a patch

Change History

03/27/08 22:52:36 changed by ericholscher

  • needs_better_patch changed.
  • component changed from django.newforms to Documentation.
  • needs_tests changed.
  • needs_docs changed.

03/27/08 22:53:06 changed by ericholscher

  • needs_docs set to 1.

06/11/08 21:08:50 changed by programmerq

  • attachment 6891.diff added.

worked up a patch

06/11/08 21:09:08 changed by programmerq

  • needs_docs deleted.
  • has_patch set to 1.
  • stage changed from Unreviewed to Ready for checkin.

06/23/08 07:57:11 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #6891 (Modelform documentation on editing an existing object needs to be updated.)




Change Properties
Action