#32933: Point users to BoundField.initial instead of 
Form.get_initial_for_field()
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Documentation        |                  Version:  dev
     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 Chris Jerdonek:

Old description:

> Currently, the documentation points users to
> `Form.get_initial_for_field(field, field_name)` to get the initial data
> for a form field. However, I think it would be better to point users to
> `BoundField.initial`, e.g. using the pattern `form[field_name].initial`.
> (`BoundField.initial` should also be added to the
> [https://docs.djangoproject.com/en/3.2/ref/forms/api/#attributes-of-
> boundfield BoundField attribute documentation], as it seems to have been
> left out.)
>
> There are a couple reasons I think users should be steered away from
> `get_initial_for_field()`. One reason is that the API is simpler because
> it doesn't require passing redundant `field` and `field_name` arguments.
> Another reason is that going through `BoundField` has the advantage of
> using the `BoundField` instance's cache, as `initial` is a cached
> property. (I'm going to be filing another ticket related to the latter
> difference, later.)

New description:

 Currently, the documentation points users to
 `Form.get_initial_for_field(field, field_name)` to get the initial data
 for a form field. However, I think it would be better to point users to
 `BoundField.initial`, e.g. using the pattern `form[field_name].initial`.
 (`BoundField.initial` should also be added to the
 [https://docs.djangoproject.com/en/3.2/ref/forms/api/#attributes-of-
 boundfield BoundField attribute documentation], as it seems to have been
 left out.)

 There are a couple reasons I think users should be steered away from
 `get_initial_for_field()`. One reason is that `BoundField'`s API is
 simpler because it doesn't require passing redundant `field` and
 `field_name` arguments. Another reason is that going through `BoundField`
 has the advantage of using the `BoundField` instance's cache, as `initial`
 is a cached property. (I'm going to be filing another ticket related to
 the latter difference, later.)

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32933#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.478b49ce1c5d1dace0e3584f2875029f%40djangoproject.com.

Reply via email to