From 15b62338021672f43edc20cdc28280446662784b Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 3 Jul 2023 12:51:37 +0100 Subject: [PATCH] update get_or_create_cid_user_exam --- generic/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/generic/models.py b/generic/models.py index 1b8148c4..2f5e6793 100644 --- a/generic/models.py +++ b/generic/models.py @@ -92,7 +92,7 @@ class Examination(models.Model): def __str__(self): return self.examination - def merge_into(self, examination_to_merge_into: Self, delete: bool=True) -> bool: + def merge_into(self, examination_to_merge_into: Self, delete: bool = True) -> bool: """Merges the current examination into another To do so it replaces all associations (many to many and foreign key relations) @@ -452,10 +452,17 @@ class ExamCollectionGenericBase(models.Model): return False def get_or_create_cid_user_exam( - self, cid_user=None, user_user=None, start_time=None + self, + cid: int | None = None, + cid_user: "CidUser | None" = None, + user_user: User | None = None, + start_time=None, ): content_type = ContentType.objects.get_for_model(self) + if cid is not None: + cid_user = CidUser.objects.filter(cid=cid).first() + if cid_user is not None: c = CidUserExam.objects.filter( content_type=content_type, object_id=self.pk, cid_user=cid_user