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.shortcuts import render, get_object_or_404, redirect
from django.contrib.contenttypes.models import ContentType
class ExaminationForm(ModelForm): class ExaminationForm(ModelForm):
class Meta: class Meta:
model = Examination model = Examination
@@ -37,10 +39,13 @@ class QuestionNoteForm(ModelForm):
if question_type == "rapid": if question_type == "rapid":
question = Rapid question = Rapid
content_type = ContentType.objects.get(model="rapid")
elif question_type == "anatomy": elif question_type == "anatomy":
question = AnatomyQuestion question = AnatomyQuestion
content_type = ContentType.objects.get(model="anatomyquestion")
elif question_type == "long": elif question_type == "long":
question = AnatomyQuestion question = Long
content_type = ContentType.objects.get(model="long")
else: else:
raise PermissionError() raise PermissionError()
@@ -48,11 +53,13 @@ class QuestionNoteForm(ModelForm):
# We get the 'initial' keyword argument or initialize it # We get the 'initial' keyword argument or initialize it
# as a dict if it didn't exist. # as a dict if it didn't exist.
#if kwargs.get("instance"): #if kwargs.get("instance"):
ModelForm.__init__(self, *args, **kwargs)
super(QuestionNoteForm, self).__init__(*args, **kwargs)
initial = kwargs.setdefault("initial", {}) initial = kwargs.setdefault("initial", {})
# The widget for a ModelMultipleChoiceField expects # The widget for a ModelMultipleChoiceField expects
# a list of primary key for the selected data. # a list of primary key for the selected data.
initial["content_type"] = question #initial["content_type"] = question
initial["content_id"] = pk #initial["content_id"] = pk
self.fields["content_type"].initial = content_type
ModelForm.__init__(self, *args, **kwargs) self.fields["object_id"].initial = pk
super(QuestionNoteForm, self).__init__(*args, **kwargs)
@@ -0,0 +1,19 @@
# Generated by Django 3.1.3 on 2021-05-05 18:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('generic', '0011_auto_20210503_1831'),
]
operations = [
migrations.AlterField(
model_name='questionnote',
name='note_type',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='generic.notetype'),
),
]
+4 -1
View File
@@ -116,7 +116,7 @@ class QuestionNote(models.Model):
complete = models.BooleanField(default=False) complete = models.BooleanField(default=False)
note_type = models.ForeignKey(NoteType, on_delete=models.CASCADE, null=True) note_type = models.ForeignKey(NoteType, on_delete=models.CASCADE, null=True, blank=True)
#def get_absolute_url(self): #def get_absolute_url(self):
# self.pk = self.rapid_id # self.pk = self.rapid_id
@@ -124,3 +124,6 @@ class QuestionNote(models.Model):
def __str__(self): def __str__(self):
return "{} [{}] {} / {}".format(self.author, self.created_on, self.note_type, self.note) return "{} [{}] {} / {}".format(self.author, self.created_on, self.note_type, self.note)
def get_absolute_url(self):
return "/"