Opened 7 years ago

Closed 7 years ago

#5364 closed (fixed)

Point to save(commit=False) in the "subset of fields" note

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

Description

I think it might be useful to point to the save(commit=False) feature of form_for_model/instance in the "subset of fields" discussion. A common scenario is when a model has a ForeignKey relation to a User object. The webmaster doesn't want to expose the User field but rather add it in after receiving the form. This field is usually required and throws an error when using save() without commit=False.

http://www.djangoproject.com/documentation/newforms/#using-a-subset-of-fields-on-the-form

Attachments (4)

5364.diff (1.1 KB) - added by PhiR 7 years ago.
modified the doc accordingly
5364.2.diff (1.1 KB) - added by PhiR 7 years ago.
modified the doc accordingly, with input from #django-sprint
5364.3.diff (1.2 KB) - added by PhiR 7 years ago.
modified the doc accordingly, with input from #django-sprint
5364.4.diff (1.2 KB) - added by PhiR 7 years ago.
one more typo :)

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by PhiR

  • Needs documentation set
  • Needs tests unset
  • Owner changed from nobody to PhiR
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

There is already a note saying that fields not in the 'fields' argument of form_for_model should have default values or allowed to be Null. But it is possible to add a value before the save() and an exemple of that should be provided. Will do after me shower :)

Changed 7 years ago by PhiR

modified the doc accordingly

comment:2 Changed 7 years ago by PhiR

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

Changed 7 years ago by PhiR

modified the doc accordingly, with input from #django-sprint

Changed 7 years ago by PhiR

modified the doc accordingly, with input from #django-sprint

comment:3 Changed 7 years ago by PhiR

  • Status changed from new to assigned

Changed 7 years ago by PhiR

one more typo :)

comment:4 Changed 7 years ago by George Vilches <gav@…>

  • Keywords sprintsept14 added

comment:5 Changed 7 years ago by russellm

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

(In [6409]) Fixed #5364 -- Clarified the warning regarding saving form_for_model forms with missing fields. Thanks to PhilR for the initial draft.

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