Opened 3 years ago
Closed 3 years ago
#32924 closed Cleanup/optimization (fixed)
Move special-case logic in BoundField.initial() to BaseForm.get_initial_for_field()
Reported by: | Chris Jerdonek | Owned by: | Chris Jerdonek |
---|---|---|---|
Component: | Forms | 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
This is another follow-up to ticket #32920.
Currently, BoundField.initial()
has logic to special-case time
and datetime
objects:
https://github.com/django/django/blob/f5669fd7b568cf8a3eda1e65c1c6fb583c7b177d/django/forms/boundfield.py#L217-L219
I noticed that this logic can be moved to BaseForm.get_initial_for_field()
, and in particular under the if callable(value)
block:
https://github.com/django/django/blob/f5669fd7b568cf8a3eda1e65c1c6fb583c7b177d/django/forms/forms.py#L496-L497
Eventually, I think it could make sense to go further and move some of this logic to a new method of the Field
class, which could permit the special-casing to be handled by overriding in sub-classes that use times and datetimes.
Change History (6)
comment:1 by , 3 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 3 years ago
Has patch: | set |
---|
comment:3 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
PR: https://github.com/django/django/pull/14641