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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32924>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:1>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/14641
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:3>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"469e76929976a7070b0bf6899a314d19e6e8e485" 469e769]:
{{{
#!CommitTicketReference repository=""
revision="469e76929976a7070b0bf6899a314d19e6e8e485"
Refs #32924 -- Changed test_get_initial_for_field() to use subTests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"0dc25526d8daaaa59968d4b1b597968e197f040c" 0dc25526]:
{{{
#!CommitTicketReference repository=""
revision="0dc25526d8daaaa59968d4b1b597968e197f040c"
Fixed #32924 -- Changed BaseForm.get_initial_for_field() to remove
microseconds when needed.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:6>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"788441c6ab4e0167aadc155a4362a87694e38aa5" 788441c]:
{{{
#!CommitTicketReference repository=""
revision="788441c6ab4e0167aadc155a4362a87694e38aa5"
Refs #32924 -- Changed test_initial_datetime_values() to use subTests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:5>