|
@@ -650,10 +650,38 @@ class AntennaAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
|
class SwitchAdmin(admin.ModelAdmin):
|
|
|
- list_display = ('name',)
|
|
|
+ list_display = ('name', 'ports_count', 'active_ports_count', 'inactive_ports_count', 'unknown_ports_count',)
|
|
|
fields = ('name', 'first_port', 'last_port', 'notes',)
|
|
|
search_fields = ('name', 'notes', 'ports__notes', 'ports__service__label',)
|
|
|
|
|
|
+ def get_queryset(self, request):
|
|
|
+ qs = super().get_queryset(request)
|
|
|
+ qs = qs.annotate(
|
|
|
+ active_ports_count=models.Count(models.Case(models.When(ports__up=True, then=models.Value('1')))),
|
|
|
+ unknown_ports_count=models.Count(models.Case(models.When(ports__up__isnull=True, then=models.Value('1')))),
|
|
|
+ inactive_ports_count=models.Count(models.Case(models.When(ports__up=False, then=models.Value('1')))),
|
|
|
+ )
|
|
|
+ return qs
|
|
|
+
|
|
|
+ def ports_count(self, switch):
|
|
|
+ return switch.last_port - switch.first_port + 1
|
|
|
+ ports_count.short_description = 'Nombre de ports'
|
|
|
+
|
|
|
+ def active_ports_count(self, switch):
|
|
|
+ return switch.active_ports_count
|
|
|
+ active_ports_count.short_description = 'up'
|
|
|
+ active_ports_count.admin_order_field = 'active_ports_count'
|
|
|
+
|
|
|
+ def inactive_ports_count(self, switch):
|
|
|
+ return switch.inactive_ports_count
|
|
|
+ inactive_ports_count.short_description = 'down'
|
|
|
+ inactive_ports_count.admin_order_field = 'inactive_ports_count'
|
|
|
+
|
|
|
+ def unknown_ports_count(self, switch):
|
|
|
+ return switch.unknown_ports_count
|
|
|
+ unknown_ports_count.short_description = 'inconnus'
|
|
|
+ unknown_ports_count.admin_order_field = 'unknown_ports_count'
|
|
|
+
|
|
|
def get_inline_instances(self, request, obj=None):
|
|
|
if obj:
|
|
|
return [ SwitchPortInline(self.model, self.admin_site) ]
|