Changes between Version 2 and Version 3 of Ticket #32933


Ignore:
Timestamp:
Jul 15, 2021, 1:45:46 PM (3 years ago)
Author:
Chris Jerdonek
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32933 – Description

    v2 v3  
    1 Currently, the documentation [https://docs.djangoproject.com/en/3.2/ref/forms/api/#django.forms.Form.get_initial_for_field 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.)
     1Currently, the documentation [https://docs.djangoproject.com/en/3.2/ref/forms/api/#django.forms.Form.get_initial_for_field 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` ([https://github.com/django/django/blob/7f33c1e22dbc34a7afae7967783725b10f1f13b1/django/forms/boundfield.py#L212-L220 link to code]), 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.)
    22
    33There 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.)
Back to Top