Add Crispy Forms integration to QuestionForm and update question_form template for improved layout and usability
This commit is contained in:
@@ -24,6 +24,8 @@ from django.forms.widgets import RadioSelect, TextInput, Textarea
|
||||
from tinymce.widgets import TinyMCE
|
||||
|
||||
from dal import autocomplete
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Layout, Fieldset, Row, Column, Submit
|
||||
|
||||
|
||||
class UserAnswerForm(ModelForm):
|
||||
@@ -105,6 +107,38 @@ class QuestionForm(ModelForm):
|
||||
widget=FilteredSelectMultiple(verbose_name="Exams", is_stacked=False),
|
||||
)
|
||||
|
||||
# Crispy Forms helper and layout
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = "post"
|
||||
self.helper.form_enctype = "multipart/form-data"
|
||||
self.helper.template_pack = "bootstrap5"
|
||||
self.helper.layout = Layout(
|
||||
Fieldset(
|
||||
"Question",
|
||||
"title",
|
||||
"stem",
|
||||
),
|
||||
Fieldset(
|
||||
"Answers",
|
||||
Row(Column("a_answer", css_class="col-6"), Column("a_feedback", css_class="col-6")),
|
||||
Row(Column("b_answer", css_class="col-6"), Column("b_feedback", css_class="col-6")),
|
||||
Row(Column("c_answer", css_class="col-6"), Column("c_feedback", css_class="col-6")),
|
||||
Row(Column("d_answer", css_class="col-6"), Column("d_feedback", css_class="col-6")),
|
||||
Row(Column("e_answer", css_class="col-6"), Column("e_feedback", css_class="col-6")),
|
||||
"best_answer",
|
||||
),
|
||||
Fieldset(
|
||||
"Feedback",
|
||||
"feedback",
|
||||
),
|
||||
Fieldset(
|
||||
"Metadata",
|
||||
Row(Column("category", css_class="col-6"), Column("exams", css_class="col-6")),
|
||||
Row(Column("open_access", css_class="col-4"), Column("frcr_appropriate", css_class="col-4")),
|
||||
),
|
||||
)
|
||||
self.helper.add_input(Submit("submit", "Submit", css_class="btn btn-primary"))
|
||||
|
||||
def save(self, commit=True):
|
||||
# Get the unsaved Pizza instance
|
||||
instance = ModelForm.save(self, False)
|
||||
|
||||
Reference in New Issue
Block a user