mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-16 22:09:25 +08:00
Also delete empty study groups when students move between groups
This commit is contained in:
parent
c140e7fc6a
commit
0007f84b47
1 changed files with 6 additions and 0 deletions
|
@ -67,6 +67,12 @@ class StudentStatusSerializer(serializers.ModelSerializer):
|
|||
# If there are no students left in the old StudyGroup, delete it
|
||||
old_study_group.delete()
|
||||
|
||||
# If student has changed study group, check if the old study_group no longer has any students
|
||||
if study_group is not old_study_group and old_study_group is not None:
|
||||
if not old_study_group.students.exists():
|
||||
# If there are no students left in the old StudyGroup, delete it
|
||||
old_study_group.delete()
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue