From 28d8371d1d145588f7099ba49f4b63dd6d092e13 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Tue, 27 Aug 2024 13:38:56 +0200 Subject: [PATCH] Delete associated Group when a Team is deleted No-Issue --- galaxy_ng/app/models/organization.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/galaxy_ng/app/models/organization.py b/galaxy_ng/app/models/organization.py index f941b700ef..b5a74d6217 100644 --- a/galaxy_ng/app/models/organization.py +++ b/galaxy_ng/app/models/organization.py @@ -6,7 +6,7 @@ from django.db import models from django.db.models import signals from django.dispatch import receiver -from django_lifecycle import AFTER_UPDATE, BEFORE_CREATE, LifecycleModelMixin, hook +from django_lifecycle import AFTER_UPDATE, AFTER_DELETE, BEFORE_CREATE, LifecycleModelMixin, hook from pulpcore.plugin.models import Group as PulpGroup from galaxy_ng.app.models.auth import Group @@ -84,6 +84,12 @@ def _rename_related_group(self, **kwargs): self.group.name = self.group_name() self.group.save() + @hook(AFTER_DELETE) + def _delete_related_group(self, **kwargs): + group = getattr(self, "group", None) + if group: + group.delete() + @receiver(signal=signals.post_save, sender=Group) @receiver(signal=signals.post_save, sender=PulpGroup)