Skip to content

Commit

Permalink
Merge pull request #218 from OpenImaging/image-related-name
Browse files Browse the repository at this point in the history
Use reverse relation to access the Evaluation for a Frame
  • Loading branch information
annehaley authored Nov 8, 2021
2 parents ed9cd4e + 11ff2f1 commit 57d649b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
23 changes: 23 additions & 0 deletions miqa/core/migrations/0019_unique_evaluation.py
Original file line number Diff line number Diff line change
@@ -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',
),
),
]
6 changes: 5 additions & 1 deletion miqa/core/models/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

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',
on_delete=models.CASCADE,
related_name='frame_evaluation',
)
evaluation_model = models.CharField(max_length=50)
results = models.JSONField()

Expand Down
11 changes: 2 additions & 9 deletions miqa/core/rest/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 57d649b

Please sign in to comment.