.
This commit is contained in:
+21
-19
@@ -5,6 +5,7 @@ from django.forms import (
|
||||
ModelChoiceField,
|
||||
ChoiceField,
|
||||
CharField,
|
||||
HiddenInput,
|
||||
)
|
||||
from django.forms import inlineformset_factory
|
||||
|
||||
@@ -32,34 +33,35 @@ class QuestionNoteForm(ModelForm):
|
||||
class Meta:
|
||||
model = QuestionNote
|
||||
fields = ["content_type", "object_id", "author", "note_type", "note"]
|
||||
widgets = {'content_type': HiddenInput(), 'object_id': HiddenInput()}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
question_type = kwargs.pop("question_type")
|
||||
pk = kwargs.pop("pk")
|
||||
|
||||
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 = Long
|
||||
content_type = ContentType.objects.get(model="long")
|
||||
else:
|
||||
raise PermissionError()
|
||||
#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 = Long
|
||||
# content_type = ContentType.objects.get(model="long")
|
||||
#else:
|
||||
# raise PermissionError()
|
||||
|
||||
get_object_or_404(question, pk=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.
|
||||
#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
|
||||
self.fields["content_type"].initial = content_type
|
||||
self.fields["object_id"].initial = pk
|
||||
#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
|
||||
#self.fields["content_type"].initial = content_type
|
||||
#self.fields["object_id"].initial = pk
|
||||
|
||||
Reference in New Issue
Block a user