From d6fab586efa285202d79032bbd608a1a735f0579 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Sat, 6 Nov 2021 12:53:10 -0400 Subject: [PATCH 1/2] Use reverse relation to access the Evaluation for a Frame --- client/src/store/index.ts | 2 +- .../core/migrations/0019_unique_evaluation.py | 23 +++++++++++++++++++ miqa/core/models/evaluation.py | 7 +++++- miqa/core/rest/frame.py | 11 ++------- 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 miqa/core/migrations/0019_unique_evaluation.py diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 6065159d..94216a81 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -336,7 +336,7 @@ const { forwardTo: currentFrame.nextFrame, upTo: currentFrame.firstFrameInPreviousScan, downTo: currentFrame.firstFrameInNextScan, - currentAutoEvaluation: currentFrame.auto_evaluation, + currentAutoEvaluation: currentFrame.frame_evaluation, autoWindow: experiment.autoWindow, autoLevel: experiment.autoLevel, }; diff --git a/miqa/core/migrations/0019_unique_evaluation.py b/miqa/core/migrations/0019_unique_evaluation.py new file mode 100644 index 00000000..8ce7b0fe --- /dev/null +++ b/miqa/core/migrations/0019_unique_evaluation.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.8 on 2021-11-06 16:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0018_image_to_frame'), + ] + + operations = [ + migrations.AlterField( + model_name='evaluation', + name='frame', + field=models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name='frame_evaluation', + to='core.frame', + ), + ), + ] diff --git a/miqa/core/models/evaluation.py b/miqa/core/models/evaluation.py index a4609133..79a1c313 100644 --- a/miqa/core/models/evaluation.py +++ b/miqa/core/models/evaluation.py @@ -5,7 +5,12 @@ class Evaluation(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) - frame = models.ForeignKey('Frame', null=False, on_delete=models.PROTECT) + frame = models.OneToOneField( + 'Frame', + null=False, + on_delete=models.CASCADE, + related_name='frame_evaluation', + ) evaluation_model = models.CharField(max_length=50) results = models.JSONField() diff --git a/miqa/core/rest/frame.py b/miqa/core/rest/frame.py index e55aa91e..8770a1cf 100644 --- a/miqa/core/rest/frame.py +++ b/miqa/core/rest/frame.py @@ -22,17 +22,10 @@ class Meta: class FrameSerializer(serializers.ModelSerializer): class Meta: model = Frame - fields = ['id', 'frame_number', 'auto_evaluation'] + fields = ['id', 'frame_number', 'frame_evaluation'] ref_name = 'scan_frame' - auto_evaluation = serializers.SerializerMethodField() - - def get_auto_evaluation(self, frame_object): - try: - evaluation_object = Evaluation.objects.get(frame=frame_object) - return EvaluationSerializer(evaluation_object).data - except Evaluation.DoesNotExist: - return None + frame_evaluation = EvaluationSerializer() class FrameViewSet(ListModelMixin, GenericViewSet): From 11ff2f142a727a8769b3052bd5b3249f0fe70c78 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Mon, 8 Nov 2021 10:16:38 -0500 Subject: [PATCH 2/2] Change according to Zach's suggestions --- miqa/core/models/evaluation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/miqa/core/models/evaluation.py b/miqa/core/models/evaluation.py index 79a1c313..a6790322 100644 --- a/miqa/core/models/evaluation.py +++ b/miqa/core/models/evaluation.py @@ -7,7 +7,6 @@ class Evaluation(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) frame = models.OneToOneField( 'Frame', - null=False, on_delete=models.CASCADE, related_name='frame_evaluation', )