From 2380020c7d9584a404fc4b52875dbe262c87a23e Mon Sep 17 00:00:00 2001 From: Ross Date: Wed, 5 May 2021 18:49:01 +0100 Subject: [PATCH] . --- generic/forms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/generic/forms.py b/generic/forms.py index 8e0eb68c..e3b103e5 100755 --- a/generic/forms.py +++ b/generic/forms.py @@ -33,6 +33,7 @@ class QuestionNoteForm(ModelForm): def __init__(self, *args, **kwargs): question_type = kwargs.pop("question_type") + pk = kwargs.pop("pk") if question_type == "rapid": question = Rapid @@ -43,13 +44,14 @@ class QuestionNoteForm(ModelForm): else: raise PermissionError() - get_object_or_404(question, pk=kwargs.pop("pk")) + get_object_or_404(question, pk=pk) # We get the 'initial' keyword argument or initialize it # as a dict if it didn't exist. initial = kwargs.setdefault("initial", {}) # The widget for a ModelMultipleChoiceField expects # a list of primary key for the selected data. - #initial["content_type"] = [t.pk for t in kwargs["instance"].exams.all()] + initial["content_type"] = question + initial["content_id"] = pk ModelForm.__init__(self, *args, **kwargs) #super(QuestionNoteForm(), self).__init__(*args, **kwargs) \ No newline at end of file