Field initial value callable should take a request object as an argument
|Reported by:||mitar||Owned by:||nobody|
|Cc:||mmitar@…||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently it is possible to define initial value for a field as a callable. But this is quite limited in use as it does not take any context in which it should run.
I am proposing that it should take a request object. In this way it is possible to set initial values based on a request. For example, based on GeoIP information. We should pass a request object to the form constructor which would then pass it along to the those callables.
I am attaching a short helper function which allows me that I define such callables already. It postprocesses the form class so that request is available to callables. So in the view it is necessary just to construct your form with:
form = initial_accepts_request(request, MyForm)()
It still allows initial values to be passed at construction time and they override callables.
But it would be much better if this would be officially supported.
Change History (10)
Changed 6 years ago by mitar
comment:1 Changed 6 years ago by mitar
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:6 Changed 3 years ago by apollo13
- Resolution set to wontfix
- Status changed from new to closed