Skip to content
Advertisement

Associate a Django Bool FormField with a submit button in a ModelForm and CBV

The view has a Boolean Field which will define if a question is OK or needs correction. The template will load two buttons to act as submit to the form, “Question is OK” and “Question needs correction”. I need to pass the value of this button as the Boolean Field value. I found the answer when using Function-based views, but I’m using Class-based views, so I don’t know how to pass the request.POST values.

Here’s my views.py and forms.py:

views.py

JavaScript

forms.py

JavaScript

and part of the template that this code will be loaded:

JavaScript

Advertisement

Answer

As Ene P told in the comments the following link solves it.

https://docs.djangoproject.com/en/3.2/topics/class-based-views/intro/#handling-forms-with-class-based-views

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement