I have a form with a field “status” that will be set by the view depending on the value of some fields of my form
is it possible to do that BEFORE form.is_valid() (otherwise the form won’t be valid)?
the only way I can think of doing that is allowing the “status” field to be blank, but that doesn’t seem good design
defining a clean() method that set those fields is a better solution?
If the status field isn’t intended be set by the user filling out the form, it probably shouldn’t be in the form at all.
If that value is later used in creating/updating a model instance or something, then it would be better to just include the value determined by your view in the form’s save method, like
form.save(status=my_status)(if it’s aModelForm) or when you’re instantiating your model, otherwise.If the user does enter the status, then you can just have a custom
clean()method that ensures it is an acceptable value.