Browse Source

vérouillage suppression tunnel / route

Élie Bouttier 6 years ago
parent
commit
70b69d6023
1 changed files with 17 additions and 0 deletions
  1. 17 0
      services/admin.py

+ 17 - 0
services/admin.py

@@ -640,6 +640,10 @@ class RouteAdmin(admin.ModelAdmin):
         return actions
 
     def has_delete_permission(self, request, obj=None):
+        if obj:
+            if obj.allocations.exists():
+                return False
+            return True
         return False
 
 
@@ -649,6 +653,19 @@ class TunnelAdmin(admin.ModelAdmin):
         ActiveTunnelFilter,
     )
 
+    def get_actions(self, request):
+        actions = super().get_actions(request)
+        if 'delete_selected' in actions:
+            del actions['delete_selected']
+        return actions
+
+    def has_delete_permission(self, request, obj=None):
+        if obj:
+            if obj.allocations.exists():
+                return False
+            return True
+        return False
+
     def active(self, obj):
         return not obj.ended
     active.short_description = 'Actif'