Opened 3 years ago

Last modified 3 years ago

#32933 closed Cleanup/optimization

Point users to BoundField.initial instead of Form.get_initial_for_field() — at Initial Version

Reported by: Chris Jerdonek Owned by: nobody
Component: Documentation 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

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 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.)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top