diff --git a/smash/web/models/study_subject.py b/smash/web/models/study_subject.py index a4d217784f01a67e34d2698777f743f5a2e06548..80d2f8eac720a303f5e6919ef05d6801ddb6cbd9 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 40c390932411e2f7a4c5bcf622927e5a5935631c..22b45738320ebdce8119126c66753f1bd054f0cb 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,