From 34e1c698dbd930624a1960ee8758e23ba94d8341 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Tue, 17 Sep 2024 10:21:18 +0200 Subject: [PATCH] feat: delete user when deleting representative --- backend/tprm/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/tprm/views.py b/backend/tprm/views.py index 934475103..0afedcd1d 100644 --- a/backend/tprm/views.py +++ b/backend/tprm/views.py @@ -56,6 +56,13 @@ class RepresentativeViewSet(BaseModelViewSet): API endpoint that allows representatives to be viewed or edited. """ + def destroy(self, request, *args, **kwargs): + instance = self.get_object() + if instance.user: + instance.user.delete() + + return super().destroy(request, *args, **kwargs) + model = Representative filterset_fields = ["entity"]