From eedf9263de9d74271e7ed0477a23e15119c402fa Mon Sep 17 00:00:00 2001 From: Carlos Vega <carlos.vega@uni.lu> Date: Mon, 6 Apr 2020 12:41:50 +0200 Subject: [PATCH] added property to get provenances --- smash/web/models/study_subject.py | 7 +++++-- smash/web/models/subject.py | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/smash/web/models/study_subject.py b/smash/web/models/study_subject.py index a4d21778..80d2f8ea 100644 --- a/smash/web/models/study_subject.py +++ b/smash/web/models/study_subject.py @@ -3,19 +3,22 @@ import logging import re from django.db import models -from web.models import VoucherType, Appointment, Location, Visit +from web.models import VoucherType, Appointment, Location, Visit, Provenance from web.models.constants import BOOL_CHOICES, SUBJECT_TYPE_CHOICES, FILE_STORAGE from django.db.models.signals import post_save from django.dispatch import receiver logger = logging.getLogger(__name__) - class StudySubject(models.Model): class Meta: app_label = 'web' + @property + def provenances(self): + return Provenance.objects.filter(modified_table=StudySubject._meta.db_table).filter(modified_table_id=self.id).order_by('-modification_date') + def finish_all_visits(self): visits = Visit.objects.filter(subject=self, is_finished=False) for visit in visits: diff --git a/smash/web/models/subject.py b/smash/web/models/subject.py index 40c39093..22b45738 100644 --- a/smash/web/models/subject.py +++ b/smash/web/models/subject.py @@ -14,6 +14,10 @@ class Subject(models.Model): class Meta: app_label = 'web' + + @property + def provenances(self): + return Provenance.objects.filter(modified_table=Subject._meta.db_table).filter(modified_table_id=self.id).order_by('-modification_date') sex = models.CharField(max_length=1, choices=SEX_CHOICES, -- GitLab