It can be seen from this: ModelChoiceField returns the value through cleaned_data to the instance of the model corresponding to the corresponding queryset. ModelMultipleChoiceField returns a list of instances of the model corresponding to the corresponding queryset through cleaned_data. Other forms use cleaned_data to return the value to define the type of its field. The documentation in Django is very clear, you can read it carefully.
We can test it using the code:
model:
As a test, we insert three rows of data into the table:
form:
In the above form, we created ModelChoiceField and ModelMutipleChoiceField. In queryset, we query objects with id less than or equal to 2.
view:
Template:
We fill in the form as follows.
The output result is:
It can be seen from this:
ModelChoiceField returns the value through cleaned_data to the instance of the model corresponding to the corresponding queryset.
ModelMultipleChoiceField returns a list of instances of the model corresponding to the corresponding queryset through cleaned_data.
Other forms use cleaned_data to return the value to define the type of its field.
The documentation in Django is very clear, you can read it carefully.