update anatomy to remove sortedm2m
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 4.1.4 on 2024-02-17 22:10
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('anatomy', '0013_rename_exam_collection_exam_examcollection'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ExamQuestionDetail',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='anatomy.exam')),
|
||||
('anatomyquestion', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='anatomy.anatomyquestion')),
|
||||
('sort_order', models.IntegerField(default=1000)),
|
||||
],
|
||||
options={
|
||||
'ordering': ('sort_order',),
|
||||
},
|
||||
),
|
||||
migrations.RunSQL(
|
||||
"""INSERT INTO anatomy_examquestiondetail
|
||||
SELECT * FROM anatomy_exam_exam_questions;"""
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.1.4 on 2024-02-17 22:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('anatomy', '0014_examquestiondetail'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='exam',
|
||||
name='exam_questions',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='exam',
|
||||
name='exam_questions',
|
||||
field=models.ManyToManyField(related_name='exams', through='anatomy.ExamQuestionDetail', to='anatomy.anatomyquestion'),
|
||||
),
|
||||
]
|
||||
+12
-3
@@ -361,14 +361,23 @@ class Answer(models.Model):
|
||||
# if self.answer:
|
||||
# self.answer.strip()
|
||||
|
||||
class ExamQuestionDetail(models.Model):
|
||||
exam = models.ForeignKey("Exam", on_delete=models.CASCADE)
|
||||
anatomyquestion = models.ForeignKey(AnatomyQuestion, on_delete=models.CASCADE)
|
||||
|
||||
sort_order = models.IntegerField(default=1000)
|
||||
|
||||
class Meta:
|
||||
ordering = ("sort_order",)
|
||||
|
||||
@reversion.register
|
||||
class Exam(ExamBase):
|
||||
app_name = "anatomy"
|
||||
|
||||
exam_questions = SortedManyToManyField(
|
||||
AnatomyQuestion, related_name="exams", blank="true"
|
||||
)
|
||||
#exam_questions = SortedManyToManyField(
|
||||
# AnatomyQuestion, related_name="exams", blank="true"
|
||||
#)
|
||||
exam_questions = models.ManyToManyField("AnatomyQuestion", through=ExamQuestionDetail, related_name="exams")
|
||||
time_limit = models.IntegerField(
|
||||
help_text="Exam time limit (in seconds)", default=5400
|
||||
)
|
||||
|
||||
@@ -30,8 +30,6 @@ from django.utils.html import mark_safe
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
import string
|
||||
from collections import defaultdict
|
||||
from helpers.images import (
|
||||
|
||||
@@ -14,7 +14,6 @@ from django.urls import reverse
|
||||
from django.views.generic.edit import CreateView
|
||||
from reversion.views import RevisionMixin
|
||||
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
from django.conf import settings
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
||||
|
||||
+15
-2
@@ -90,7 +90,7 @@ from rapids.models import Rapid as RapidQuestion, RapidImage
|
||||
from rapids.models import Exam as RapidsExam
|
||||
from longs.models import Long as LongQuestion, LongSeries
|
||||
from longs.models import Exam as LongsExam
|
||||
from anatomy.models import AnatomyQuestion as AnatomyQuestion
|
||||
from anatomy.models import AnatomyQuestion as AnatomyQuestion, ExamQuestionDetail
|
||||
from anatomy.models import Exam as AnatomyExam
|
||||
from sbas.models import Question as SbasQuestion
|
||||
from sbas.models import Exam as SbasExam
|
||||
@@ -859,7 +859,7 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
to_attr="prefetched_primary_answer"
|
||||
# queryset=self.Answer.objects.filter(),
|
||||
),
|
||||
)
|
||||
).order_by("examquestiondetail__sort_order")
|
||||
)
|
||||
elif self.app_name == "longs":
|
||||
questions = (
|
||||
@@ -1213,8 +1213,21 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
case_detail = CaseDetail.objects.get(case=case, collection=exam)
|
||||
case_detail.sort_order = n
|
||||
case_detail.save()
|
||||
|
||||
else:
|
||||
exam.exam_questions.set(objects)
|
||||
for n, question in enumerate(objects):
|
||||
match self.app_name:
|
||||
case "anatomy":
|
||||
question_detail = ExamQuestionDetail.objects.get(
|
||||
anatomyquestion=question, exam=exam
|
||||
)
|
||||
case _:
|
||||
data = {"status": "error"}
|
||||
return JsonResponse(data, status=200)
|
||||
question_detail.sort_order = n
|
||||
question_detail.save()
|
||||
|
||||
exam.save()
|
||||
data = {"status": "success"}
|
||||
return JsonResponse(data, status=200)
|
||||
|
||||
Reference in New Issue
Block a user