Skip to content

Commit

Permalink
exclude parent study
Browse files Browse the repository at this point in the history
  • Loading branch information
atarkowska committed Apr 13, 2018
1 parent 835da07 commit 30236e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions emgapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import logging

from django.db.models import Q

from rest_framework_json_api import serializers
from rest_framework_json_api import relations

Expand Down Expand Up @@ -1033,8 +1035,10 @@ def get_studies(self, obj):
.filter(study_id=obj.study_id) \
.values("sample_id")
studies = emg_models.StudySample.objects \
.filter(sample_id__in=samples) \
.values("study_id")
.filter(
Q(sample_id__in=samples),
~Q(study_id=obj.study_id)
).values("study_id")
queryset = emg_models.Study.objects.filter(study_id__in=studies) \
.available(self.context['request']).distinct()
return queryset
7 changes: 5 additions & 2 deletions emgapi/views_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from django.db.models import Prefetch
from django.shortcuts import get_object_or_404
from django.db.models import Q

from django_filters.rest_framework import DjangoFilterBackend

Expand Down Expand Up @@ -151,8 +152,10 @@ def get_queryset(self):
.filter(study_id=study.study_id) \
.values("sample_id")
studies = emg_models.StudySample.objects \
.filter(sample_id__in=samples) \
.values("study_id")
.filter(
Q(sample_id__in=samples),
~Q(study_id=study.study_id)
).values("study_id")
queryset = emg_models.Study.objects.filter(study_id__in=studies) \
.available(self.request).distinct()
return queryset
Expand Down

0 comments on commit 30236e2

Please sign in to comment.