[Answered ]-Defining the value of a field in the view before validating a form

2👍

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

0👍

Then you should init form with this status value and then hide field.

class StatusForm(forms.ModelForm):
    def __init__(self, *arg, **kwargs):
        super(StatusForm, self).__init__(*arg, **kwargs)
        # set needed value here and hide field

Leave a comment