.
This commit is contained in:
+14
-16
@@ -40,9 +40,8 @@ class MarkAnatomyQuestionForm(Form):
|
||||
|
||||
class AnatomyQuestionForm(ModelForm):
|
||||
|
||||
exams = ModelMultipleChoiceField(queryset=Exam.objects.all())
|
||||
exams = ModelMultipleChoiceField(required=False, queryset=Exam.objects.all())
|
||||
|
||||
|
||||
class Media:
|
||||
# Django also includes a few javascript files necessary
|
||||
# for the operation of this form element. You need to
|
||||
@@ -89,20 +88,18 @@ class AnatomyQuestionForm(ModelForm):
|
||||
queryset=BodyPart.objects.all(),
|
||||
)
|
||||
|
||||
#self.fields["exams"] = ModelChoiceField(
|
||||
# self.fields["exams"] = ModelChoiceField(
|
||||
# required=False,
|
||||
# queryset=Exam.objects.all(),
|
||||
#)
|
||||
# )
|
||||
|
||||
|
||||
if kwargs.get('instance'):
|
||||
if kwargs.get("instance"):
|
||||
# We get the 'initial' keyword argument or initialize it
|
||||
# as a dict if it didn't exist.
|
||||
initial = kwargs.setdefault('initial', {})
|
||||
initial = kwargs.setdefault("initial", {})
|
||||
# The widget for a ModelMultipleChoiceField expects
|
||||
# a list of primary key for the selected data.
|
||||
initial['exams'] = [t.pk for t in
|
||||
kwargs['instance'].exams.all()]
|
||||
initial["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||
|
||||
ModelForm.__init__(self, *args, **kwargs)
|
||||
|
||||
@@ -117,13 +114,13 @@ class AnatomyQuestionForm(ModelForm):
|
||||
old_save_m2m()
|
||||
# This is where we actually link the pizza with toppings
|
||||
instance.exams.clear()
|
||||
for exam in self.cleaned_data['exams']:
|
||||
for exam in self.cleaned_data["exams"]:
|
||||
instance.exams.add(exam)
|
||||
|
||||
self.save_m2m = save_m2m
|
||||
|
||||
# Do we need to save all changes now?
|
||||
#if commit:
|
||||
# if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
|
||||
@@ -152,7 +149,7 @@ AnswerFormSet = inlineformset_factory(
|
||||
fields=["answer", "status"],
|
||||
widgets={
|
||||
"answer": Textarea(
|
||||
attrs={"required": "true", "minlength": 2, "maxlength": 500, 'rows': 3}
|
||||
attrs={"required": "true", "minlength": 2, "maxlength": 500, "rows": 3}
|
||||
)
|
||||
},
|
||||
exclude=[],
|
||||
@@ -168,7 +165,7 @@ AnswerUpdateFormSet = inlineformset_factory(
|
||||
fields=["answer", "status"],
|
||||
widgets={
|
||||
"answer": Textarea(
|
||||
attrs={"required": "true", "minlength": 2, "maxlength": 500, 'rows': 3}
|
||||
attrs={"required": "true", "minlength": 2, "maxlength": 500, "rows": 3}
|
||||
)
|
||||
},
|
||||
exclude=[],
|
||||
@@ -178,19 +175,20 @@ AnswerUpdateFormSet = inlineformset_factory(
|
||||
field_classes="testing",
|
||||
)
|
||||
|
||||
|
||||
class ExaminationForm(ModelForm):
|
||||
class Meta:
|
||||
model = Examination
|
||||
fields = ['examination']
|
||||
fields = ["examination"]
|
||||
|
||||
|
||||
class StructureForm(ModelForm):
|
||||
class Meta:
|
||||
model = Structure
|
||||
fields = ['structure']
|
||||
fields = ["structure"]
|
||||
|
||||
|
||||
class BodyPartForm(ModelForm):
|
||||
class Meta:
|
||||
model = BodyPart
|
||||
fields = ['bodypart']
|
||||
fields = ["bodypart"]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.3 on 2020-12-28 22:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('anatomy', '0014_exam_time_limit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='exam',
|
||||
name='time_limit',
|
||||
field=models.IntegerField(default=5400, help_text='Exam time limit (in seconds)'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
# Generated by Django 3.1.3 on 2020-12-28 22:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('physics', '0002_auto_20201216_2207'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='question',
|
||||
name='a_feedback',
|
||||
field=models.TextField(blank=True, help_text='Feedback for answer'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='question',
|
||||
name='b_feedback',
|
||||
field=models.TextField(blank=True, help_text='Feedback for answer'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='question',
|
||||
name='c_feedback',
|
||||
field=models.TextField(blank=True, help_text='Feedback for answer'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='question',
|
||||
name='d_feedback',
|
||||
field=models.TextField(blank=True, help_text='Feedback for answer'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='question',
|
||||
name='e_feedback',
|
||||
field=models.TextField(blank=True, help_text='Feedback for answer'),
|
||||
),
|
||||
]
|
||||
@@ -33,6 +33,10 @@ class Question(models.Model):
|
||||
a_answer = models.BooleanField(
|
||||
help_text=answer_help_text, default=True
|
||||
)
|
||||
a_feedback = models.TextField(
|
||||
blank=True,
|
||||
help_text="Feedback for answer",
|
||||
)
|
||||
|
||||
b = models.TextField(
|
||||
blank=False,
|
||||
@@ -41,6 +45,10 @@ class Question(models.Model):
|
||||
b_answer = models.BooleanField(
|
||||
help_text=answer_help_text, default=True
|
||||
)
|
||||
b_feedback = models.TextField(
|
||||
blank=True,
|
||||
help_text="Feedback for answer",
|
||||
)
|
||||
|
||||
c = models.TextField(
|
||||
blank=False,
|
||||
@@ -49,6 +57,10 @@ class Question(models.Model):
|
||||
c_answer = models.BooleanField(
|
||||
help_text=answer_help_text, default=True
|
||||
)
|
||||
c_feedback = models.TextField(
|
||||
blank=True,
|
||||
help_text="Feedback for answer",
|
||||
)
|
||||
|
||||
d = models.TextField(
|
||||
blank=False,
|
||||
@@ -57,6 +69,10 @@ class Question(models.Model):
|
||||
d_answer = models.BooleanField(
|
||||
help_text=answer_help_text, default=True
|
||||
)
|
||||
d_feedback = models.TextField(
|
||||
blank=True,
|
||||
help_text="Feedback for answer",
|
||||
)
|
||||
|
||||
e = models.TextField(
|
||||
blank=False,
|
||||
@@ -65,6 +81,10 @@ class Question(models.Model):
|
||||
e_answer = models.BooleanField(
|
||||
help_text=answer_help_text, default=True
|
||||
)
|
||||
e_feedback = models.TextField(
|
||||
blank=True,
|
||||
help_text="Feedback for answer",
|
||||
)
|
||||
|
||||
created_date = models.DateTimeField(default=timezone.now)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user