From 2728d6caf13d706ff602520047291ced7744389e Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 29 Nov 2020 10:08:50 +0000 Subject: [PATCH] switch exam questions to a sorted m2m --- anatomy/migrations/0006_auto_20201129_0955.py | 25 +++++++++++++++++++ anatomy/models.py | 4 ++- rad/settings.py | 1 + requirements.txt | 3 ++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 anatomy/migrations/0006_auto_20201129_0955.py diff --git a/anatomy/migrations/0006_auto_20201129_0955.py b/anatomy/migrations/0006_auto_20201129_0955.py new file mode 100644 index 00000000..de49928d --- /dev/null +++ b/anatomy/migrations/0006_auto_20201129_0955.py @@ -0,0 +1,25 @@ +# Generated by Django 3.1.3 on 2020-11-29 09:55 + +from django.db import migrations, models +import sortedm2m.fields +from sortedm2m.operations import AlterSortedManyToManyField + + +class Migration(migrations.Migration): + + dependencies = [ + ('anatomy', '0005_auto_20201126_1730'), + ] + + operations = [ + #migrations.AddField( + # model_name='anatomyquestion', + # name='open_access', + # field=models.BooleanField(default=True, help_text='If an question should be freely available to browse'), + #), + AlterSortedManyToManyField( + model_name='exam', + name='exam_questions', + field=sortedm2m.fields.SortedManyToManyField(blank='true', help_text=None, related_name='exams', to='anatomy.AnatomyQuestion'), + ), + ] diff --git a/anatomy/models.py b/anatomy/models.py index 0c911b3b..5eadacb8 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -9,6 +9,8 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ +from sortedm2m.fields import SortedManyToManyField + image_storage = FileSystemStorage( # Physical file location ROOT location=u"{0}/anatomy/".format(settings.MEDIA_ROOT), @@ -201,7 +203,7 @@ class Answer(models.Model): class Exam(models.Model): name = models.CharField(max_length=200) - exam_questions = models.ManyToManyField(AnatomyQuestion, + exam_questions = SortedManyToManyField(AnatomyQuestion, related_name="exams", blank="true") active = models.BooleanField(help_text="If an exam should be available", diff --git a/rad/settings.py b/rad/settings.py index 27cd4cf7..6177fca3 100644 --- a/rad/settings.py +++ b/rad/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ "easy_thumbnails", "filer", "mptt", + "sortedm2m", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/requirements.txt b/requirements.txt index 90376ccf..849d1206 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ pandas django-tables2 django-filter django-filer -psycopg2-binary \ No newline at end of file +psycopg2-binary +django-sortedm2m \ No newline at end of file