[Django] #35748: Document that Field.formfield() may return None

12 views
Skip to first unread message

Django

unread,
Sep 9, 2024, 9:51:16 AM9/9/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Type:
| Cleanup/optimization
Status: new | Component: Database
| layer (models, ORM)
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
The
[https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.formfield
current documentation] only states that a form field should be returned.
`None` is also an allowed return value,
[https://github.com/django/django/blob/cdbd31960e0cf41063b3efac97292ee0ccc262bb/django/db/models/fields/__init__.py#L2828-L2829
as used by AutoFieldMixin], used to
[https://github.com/django/django/blob/cdbd31960e0cf41063b3efac97292ee0ccc262bb/django/forms/models.py#L236-L248
ignore the field] when constructing the model form.
--
Ticket URL: <https://code.djangoproject.com/ticket/35748>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 9, 2024, 9:52:11 AM9/9/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Adam Johnson:

Old description:

> The
> [https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.formfield
> current documentation] only states that a form field should be returned.
> `None` is also an allowed return value,
> [https://github.com/django/django/blob/cdbd31960e0cf41063b3efac97292ee0ccc262bb/django/db/models/fields/__init__.py#L2828-L2829
> as used by AutoFieldMixin], used to
> [https://github.com/django/django/blob/cdbd31960e0cf41063b3efac97292ee0ccc262bb/django/forms/models.py#L236-L248
> ignore the field] when constructing the model form.

New description:
(Updating django-stubs types [https://github.com/typeddjango/django-
stubs/pull/2363 in this PR].)

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:1>

Django

unread,
Sep 9, 2024, 10:28:17 AM9/9/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

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
--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:2>

Django

unread,
Sep 9, 2024, 10:56:43 AM9/9/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Johnson):

Yes, let’s update both the reference doc section and add an example under
“Specifying the form field for a model field”.
--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:3>

Django

unread,
Sep 10, 2024, 10:58:20 AM9/10/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* owner: (none) => Clifford Gama
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:4>

Django

unread,
Sep 10, 2024, 4:51:50 PM9/10/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* has_patch: 0 => 1

Comment:

PR https://github.com/django/django/pull/18570
--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:5>

Django

unread,
Sep 19, 2024, 9:06:57 AM9/19/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:6>

Django

unread,
Sep 19, 2024, 9:19:18 AM9/19/24
to django-...@googlegroups.com
#35748: Document that Field.formfield() may return None
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"e1d226bc1c52a0165164e5b34fef1d336050ca60" e1d226bc]:
{{{#!CommitTicketReference repository=""
revision="e1d226bc1c52a0165164e5b34fef1d336050ca60"
Fixed #35748 -- Documented that fields are excluded from a ModelForm when
formfield() returns None.

Co-authored-by: Sarah Boyce <42296566+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35748#comment:7>
Reply all
Reply to author
Forward
0 new messages