Opened 2 months ago
Closed 2 months ago
#35746 closed Cleanup/optimization (needsinfo)
make the form.cleaned_data attribute of form available in the __init__
Reported by: | piscvau | Owned by: | |
---|---|---|---|
Component: | Forms | Version: | 5.0 |
Severity: | Normal | Keywords: | clean_field_name, form.full_clean |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello
form.clean_field_name
functions have no parameter passed to it as indicated in the documentation and need to access the form.cleaned_data
dictionary. However this cleaned_data dictionary is not created in the __init__
of the form but only in the full_clean method of the form.
the need:
in the form.__init__
, add closure functions as clean_field_name functions and use the cleaned_data dictionary as a free variable of this closure function. However this is not possible because the cleaned_data_dictionary is not yet created.
Suggested patch :
create the cleaned_data.attribute in the __init__
instead of the full_clean
Change History (2)
comment:1 by , 2 months ago
Description: | modified (diff) |
---|
comment:2 by , 2 months ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
I think what you're trying to say is that you need to reference
self.cleaned_data
inclean_<fieldname>()
As per the docs, this should be possible: https://docs.djangoproject.com/en/5.1/ref/forms/validation/#form-and-field-validation
Feel free to write a test/share some code if you think you've found a bug here