Validated field forms

Hello I have a form with a boolean field and a date field.

    Suspended = models.BooleanField(default=False)
    SuspendedData = models.DateField(blank=True, null=True)

When the SuspendedField is True it should enable the SuspendedDateField and when it is False it should disable the SuspendedDateFields.
In the frontEnd I inserted a js func and it works, for more control, I would like to insert the same control also in the backEnd but I am not clear if it should be inserted in the .Form file or in the view
Thanks

If I were doing this, I’d create a clean method for the form.

(You could handle this in the __init__ method, but that feels too “manual” to me.)

Sorry I didn’t understand the answer.
A clarification init is the func to prepare the data in the initial stage ?
The check on the backend is later
I am new to python and the flow of operations to be performed is still not clear to me. I was thinking about the view since in the post function you save the movement
Is there any link to read where to understand the right way to approach the validation of the various fields ?

First, I suggest you read the full page on Working with forms and then Form and field validation.

Briefly, a Django form:

  • Defines fields
  • Generates HTML
  • Validates submitted data
  • Populates the fields with validated and cleaned data

This is not completely accurate. The __init__ method is a method called when an instance of a class is created.

This line:
form = MyForm()
and this line:
form = MyForm(request.POST)

are each going to call the __init__ method of the class, because each line is creating a separate instance of the class.

For more information on Python classes, see 9. Classes — Python 3.12.4 documentation

I put the field control in the clean function