|
@@ -44,10 +44,10 @@ class IPResourceManager(models.Manager):
|
|
|
# On rajoute une super annotation « in_use » pour savoir si l’IP est dispo ou non :-)
|
|
|
qs = qs.annotate(
|
|
|
in_use_by_service=models.Exists(
|
|
|
- ServiceAllocation.objects.filter(resource=models.OuterRef('pk'), active=True)
|
|
|
+ ServiceAllocation.objects.filter(Q(resource=models.OuterRef('pk')) & get_active_filter())
|
|
|
),
|
|
|
in_use_by_antenna=models.Exists(
|
|
|
- ServiceAllocation.objects.filter(resource=models.OuterRef('pk'), active=True)
|
|
|
+ ServiceAllocation.objects.filter(Q(resource=models.OuterRef('pk')) & get_active_filter())
|
|
|
)
|
|
|
)
|
|
|
qs = qs.annotate(
|
|
@@ -77,13 +77,13 @@ class ActiveServiceManager(models.Manager):
|
|
|
def get_queryset(self):
|
|
|
qs = super().get_queryset()
|
|
|
qs = qs.annotate(
|
|
|
- active=models.Case(
|
|
|
+ has_active_allocation=models.Case(
|
|
|
models.When(get_active_filter('allocation'), then=True),
|
|
|
default=False,
|
|
|
output_field=models.BooleanField()
|
|
|
)
|
|
|
)
|
|
|
- qs = qs.order_by('pk', '-active').distinct() # complicated things here, do not touch if you're not sure
|
|
|
+ qs = qs.order_by('pk', '-has_active_allocation').distinct() # complicated things here, do not touch if you're not sure
|
|
|
return qs
|
|
|
|
|
|
|
|
@@ -154,7 +154,7 @@ class Service(models.Model):
|
|
|
raise ValidationError("Un service du même type existe déjà avec ce label.")
|
|
|
|
|
|
def is_active(self):
|
|
|
- return self.active
|
|
|
+ return self.has_active_allocation
|
|
|
is_active.boolean = True
|
|
|
is_active.short_description = 'Actif'
|
|
|
|