From 84e33d7ca66be0aeb760974a93e4333a204c8382 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Wed, 19 Jul 2023 15:43:38 +0800 Subject: [PATCH] Skip updating a subject if it already exists with the same year level, semester, and course postmigration --- stude/subjects/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stude/subjects/models.py b/stude/subjects/models.py index ddb060b..5a85d17 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -130,6 +130,9 @@ def populate_subjects(sender, **kwargs): if (Subject.objects.filter(name=subject_name).exists()): SUBJECT = Subject.objects.filter(name=subject_name ).first() + if (Subject.objects.filter(name=subject_name, year_levels=year_level, semesters=semester).exists()): + # print('Duplicate subject') + continue SUBJECT.courses.add(course) SUBJECT.year_levels.add(year_level) SUBJECT.semesters.add(semester)