From 46c707ac8a3e67ebe6d1f5cd5225d9ad4a17c290 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 28 Dec 2020 22:40:42 +0000 Subject: [PATCH] . --- anatomy/forms.py | 30 +++++++-------- anatomy/migrations/0015_auto_20201228_2235.py | 18 +++++++++ physics/migrations/0003_auto_20201228_2235.py | 38 +++++++++++++++++++ physics/models.py | 20 ++++++++++ 4 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 anatomy/migrations/0015_auto_20201228_2235.py create mode 100644 physics/migrations/0003_auto_20201228_2235.py diff --git a/anatomy/forms.py b/anatomy/forms.py index 01886f65..f57e961a 100644 --- a/anatomy/forms.py +++ b/anatomy/forms.py @@ -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'] \ No newline at end of file + fields = ["bodypart"] diff --git a/anatomy/migrations/0015_auto_20201228_2235.py b/anatomy/migrations/0015_auto_20201228_2235.py new file mode 100644 index 00000000..db9cf541 --- /dev/null +++ b/anatomy/migrations/0015_auto_20201228_2235.py @@ -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)'), + ), + ] diff --git a/physics/migrations/0003_auto_20201228_2235.py b/physics/migrations/0003_auto_20201228_2235.py new file mode 100644 index 00000000..6041896a --- /dev/null +++ b/physics/migrations/0003_auto_20201228_2235.py @@ -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'), + ), + ] diff --git a/physics/models.py b/physics/models.py index 7c08e20e..a3ed91d7 100644 --- a/physics/models.py +++ b/physics/models.py @@ -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)