Skip updating a subject if it already exists with the same year level, semester, and course postmigration

This commit is contained in:
Keannu Bernasol 2023-07-19 15:43:38 +08:00
parent 1c35e95f21
commit 84e33d7ca6

View file

@ -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)