From 986cdcd90a437e76dac35d7570ed98f682ef95da Mon Sep 17 00:00:00 2001 From: detraz Date: Sun, 17 Mar 2019 17:56:46 +0100 Subject: [PATCH] Mass delete machine intelligent function --- machines/models.py | 10 ++++++++++ users/models.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/machines/models.py b/machines/models.py index c16e57a6..61834149 100644 --- a/machines/models.py +++ b/machines/models.py @@ -224,6 +224,16 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model): """Return a name : user provided name or first interface name""" return self.name or self.short_name + @classmethod + def mass_delete(cls, machine_queryset): + """Mass delete for machine queryset""" + Domain.objects.filter(cname__interface_parent__machine__in=machine_queryset)._raw_delete(machine_queryset.db) + Domain.objects.filter(interface_parent__machine__in=machine_queryset)._raw_delete(machine_queryset.db) + Ipv6List.objects.filter(interface__machine__in=machine_queryset)._raw_delete(machine_queryset.db) + Interface.objects.filter(machine__in=machine_queryset).filter(port_lists__isnull=False).delete() + Interface.objects.filter(machine__in=machine_queryset)._raw_delete(machine_queryset.db) + machine_queryset._raw_delete(machine_queryset.db) + @cached_property def all_complete_names(self): """Renvoie tous les tls complets de la machine""" diff --git a/users/models.py b/users/models.py index bc959a21..c553acf4 100755 --- a/users/models.py +++ b/users/models.py @@ -576,7 +576,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, def mass_delete_data(cls, queryset_users): """This users will be completely archived, so only keep mandatory data""" cls.mass_disable_email(queryset_users) - Machine.objects.filter(user__in=queryset_users).delete() + Machine.mass_delete(Machine.objects.filter(user__in=queryset_users)) cls.ldap_delete_users(queryset_users) def disable_email(self):