Browse Source

fix antenne prefix filter

Élie Bouttier 7 years ago
parent
commit
9c7e8c13e6
1 changed files with 5 additions and 4 deletions
  1. 5 4
      services/admin.py

+ 5 - 4
services/admin.py

@@ -32,13 +32,14 @@ class ResourceInUseFilter(admin.SimpleListFilter):
         if self.value() == '1': # disponible
             return queryset.filter(available_filter)
 
+
 class AntennaPrefixFilter(admin.SimpleListFilter):
     title = 'préfix'
     parameter_name = 'prefix'
 
     def lookups(self, request, model_admin):
-        resources = AntennaAllocation.actives.filter(active=True).values_list('resource')
-        prefixes = IPPrefix.objects.filter(ipresource=resources).values_list('pk', 'prefix')
+        resources = AntennaAllocation.actives.filter(active=True).values_list('resource__pk', flat=True)
+        prefixes = IPPrefix.objects.filter(ipresource__in=resources).values_list('pk', 'prefix').distinct()
         return prefixes
 
     def queryset(self, request, queryset):
@@ -47,8 +48,8 @@ class AntennaPrefixFilter(admin.SimpleListFilter):
         except TypeError:
             pass
         else:
-            allocations = AntennaAllocation.actives.filter(active=True, resource__prefixes__pk=prefix)
-            queryset = queryset.filter(allocation=allocations)
+            allocations = AntennaAllocation.actives.filter(active=True, resource__prefixes__pk=prefix).values_list('pk', flat=True)
+            queryset = queryset.filter(allocation__in=allocations)
         return queryset