Opened 3 months ago

Closed 3 months ago

#35748 closed Cleanup/optimization (fixed)

Document that Field.formfield() may return None

Reported by: Adam Johnson Owned by: Clifford Gama
Component: Database layer (models, ORM) Version: dev
Severity: Normal 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 (last modified by Adam Johnson)

The current documentation only states that a form field should be returned. None is also an allowed return value, as used by AutoFieldMixin, used to ignore the field when constructing the model form.

(Updating django-stubs types in this PR.)

Change History (7)

comment:1 by Adam Johnson, 3 months ago

Description: modified (diff)

comment:2 by Sarah Boyce, 3 months ago

Triage Stage: UnreviewedAccepted

Be good to say somewhere that overwriting this to return None will make it an ignored form field
Might belong here: https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#specifying-form-field-for-model-field

comment:3 by Adam Johnson, 3 months ago

Yes, let’s update both the reference doc section and add an example under “Specifying the form field for a model field”.

comment:4 by Clifford Gama, 3 months ago

Owner: set to Clifford Gama
Status: newassigned

comment:6 by Sarah Boyce, 3 months ago

Triage Stage: AcceptedReady for checkin

comment:7 by Sarah Boyce <42296566+sarahboyce@…>, 3 months ago

Resolution: fixed
Status: assignedclosed

In e1d226bc:

Fixed #35748 -- Documented that fields are excluded from a ModelForm when formfield() returns None.

Co-authored-by: Sarah Boyce <42296566+sarahboyce@…>

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