Browse Source

utilisation de l’active manager

Élie Bouttier 7 years ago
parent
commit
1705bc78a5
1 changed files with 2 additions and 3 deletions
  1. 2 3
      services/models.py

+ 2 - 3
services/models.py

@@ -30,13 +30,12 @@ class IPResourceManager(models.Manager):
     def get_queryset(self):
         qs = super().get_queryset()
         # On rajoute une super annotation « in_use » pour savoir si l’IP est dispo ou non :-)
-        query = Q(resource=models.OuterRef('pk')) & get_active_filter()
         qs = qs.annotate(
                     in_use_by_service=models.Exists(
-                        ServiceAllocation.objects.filter(query)
+                        ServiceAllocation.actives.filter(resource=models.OuterRef('pk'), active=True)
                     ),
                     in_use_by_antenna=models.Exists(
-                        AntennaAllocation.objects.filter(query)
+                        ServiceAllocation.actives.filter(resource=models.OuterRef('pk'), active=True)
                     )
         )
         qs = qs.annotate(