Implement primary answer management with HTMX support, including form for selecting or creating answers and display templates

This commit is contained in:
Ross
2026-02-16 09:46:57 +00:00
parent ec03def164
commit 17d3b4206a
7 changed files with 165 additions and 3 deletions
+16 -1
View File
@@ -290,4 +290,19 @@ class ExamGroupsForm(ExamGroupsFormMixin):
class SuggestIncorrectAnswerForm(ModelForm):
class Meta:
model = AnatomyQuestion
fields = ["answer_suggest_incorrect"]
fields = ["answer_suggest_incorrect"]
class PrimaryAnswerForm(Form):
existing_answer = ChoiceField(required=False, choices=[], label="Use existing answer")
new_answer = CharField(required=False, widget=Textarea(attrs={"rows":3}), label="Or create new primary answer")
def __init__(self, *args, **kwargs):
question = kwargs.pop("question", None)
super().__init__(*args, **kwargs)
choices = [("", "-- choose existing --")]
if question is not None:
# Only include existing non-proposed CORRECT answers, ordered by answer text
for a in question.answers.filter(proposed=False, status=Answer.MarkOptions.CORRECT).order_by('answer'):
choices.append((str(a.pk), a.answer))
self.fields["existing_answer"].choices = choices