This commit is contained in:
Ross
2021-05-05 19:31:36 +01:00
parent 0bb042f9ac
commit 69753d176c
3 changed files with 37 additions and 8 deletions
+13 -6
View File
@@ -21,6 +21,8 @@ from longs.models import Long
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.contenttypes.models import ContentType
class ExaminationForm(ModelForm):
class Meta:
model = Examination
@@ -37,10 +39,13 @@ class QuestionNoteForm(ModelForm):
if question_type == "rapid":
question = Rapid
content_type = ContentType.objects.get(model="rapid")
elif question_type == "anatomy":
question = AnatomyQuestion
content_type = ContentType.objects.get(model="anatomyquestion")
elif question_type == "long":
question = AnatomyQuestion
question = Long
content_type = ContentType.objects.get(model="long")
else:
raise PermissionError()
@@ -48,11 +53,13 @@ class QuestionNoteForm(ModelForm):
# We get the 'initial' keyword argument or initialize it
# as a dict if it didn't exist.
#if kwargs.get("instance"):
ModelForm.__init__(self, *args, **kwargs)
super(QuestionNoteForm, self).__init__(*args, **kwargs)
initial = kwargs.setdefault("initial", {})
# The widget for a ModelMultipleChoiceField expects
# a list of primary key for the selected data.
initial["content_type"] = question
initial["content_id"] = pk
ModelForm.__init__(self, *args, **kwargs)
super(QuestionNoteForm, self).__init__(*args, **kwargs)
#initial["content_type"] = question
#initial["content_id"] = pk
self.fields["content_type"].initial = content_type
self.fields["object_id"].initial = pk