Django

Code

Ticket #10845 (closed: fixed)

Opened 1 year ago

Last modified 10 months ago

The use of "Instance" in "Creating Forms from Models" is confusing.

Reported by: ElfSternberg Assigned to: jacob
Milestone: 1.1 Component: Documentation
Version: 1.0 Keywords: grammar
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In the section "Using a subset of fields on a form," the example contains the text:

instance = Instance(required_field='value')
form = InstanceForm(request.POST, instance=instance)

The use of "instance" here as the lvalue of Instance is a poor choice. For someone skimming through the article looking just for the syntax for a subset of fields on a form, and who may have missed the text earlier in the article about the instance keyword, this seems to imply that the keyword argument might be some lowercase variant of the Model name. I strongly suggest an alternative example:

example = Example(required_field='value')
form = ExampleForm(request.POST, instance=example)

Which would make it much more clear that "instance" is the kwarg, and the kwarg is not generated dynamically.

Attachments

partial_modelform_note.diff (1.1 kB) - added by adurdin on 05/07/09 10:21:20.
Docs patch

Change History

04/22/09 14:16:16 changed by Alex

  • needs_better_patch changed.
  • needs_docs changed.
  • needs_tests changed.
  • milestone changed from 1.0.3 to 1.1.

04/22/09 18:06:12 changed by jacob

  • stage changed from Unreviewed to Accepted.

05/07/09 10:21:20 changed by adurdin

  • attachment partial_modelform_note.diff added.

Docs patch

05/07/09 10:22:19 changed by adurdin

  • stage changed from Accepted to Ready for checkin.

Rather than use the meaningless names "Example", I used the same Author models as used in the docs up to this point for clarity.

05/11/09 01:55:57 changed by jacob

  • owner changed from nobody to jacob.
  • status changed from new to assigned.

06/08/09 23:30:36 changed by ramiro

  • has_patch set to 1.

06/10/09 07:46:04 changed by russellm

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

(In [10972]) Fixed #10845 -- Clarified the examples for using ModelForms? with fields or exclude specified. Thanks to Andrew Durdin for the suggestion.

06/10/09 07:54:16 changed by russellm

(In [10975]) [1.0.X] Fixed #10845 -- Clarified the examples for using ModelForms? with fields or exclude specified. Thanks to Andrew Durdin for the suggestion.

Merge of r10972 from trunk.


Add/Change #10845 (The use of "Instance" in "Creating Forms from Models" is confusing.)




Change Properties
Action