diff --git a/netbox_cmdb/netbox_cmdb/admin.py b/netbox_cmdb/netbox_cmdb/admin.py index a5ace97..e3cb712 100644 --- a/netbox_cmdb/netbox_cmdb/admin.py +++ b/netbox_cmdb/netbox_cmdb/admin.py @@ -185,6 +185,8 @@ class SNMPAdmin(BaseAdmin): "contact", ) + search_fields = ("device__name", "location") + def community_list_display(self, obj): return ", ".join([str(community) for community in obj.community_list.all()]) diff --git a/netbox_cmdb/netbox_cmdb/filtersets.py b/netbox_cmdb/netbox_cmdb/filtersets.py index 05d5933..d5edcc5 100644 --- a/netbox_cmdb/netbox_cmdb/filtersets.py +++ b/netbox_cmdb/netbox_cmdb/filtersets.py @@ -1,5 +1,6 @@ import django_filters from django.db.models import Q +from netbox_cmdb.models.snmp import SNMP from tenancy.filtersets import TenancyFilterSet from utilities.filters import MultiValueCharFilter @@ -179,3 +180,21 @@ def search(self, queryset, name, value): return queryset.filter( Q(device__name__icontains=value) | Q(name__icontains=value) ).distinct() + + +class SNMPFilterSet(ChangeLoggedModelFilterSet): + """AS number filterset.""" + + q = django_filters.CharFilter( + method="search", + label="Search", + ) + + class Meta: + model = SNMP + fields = ["device"] + + def search(self, queryset, name, value): + if not value.strip(): + return queryset + return queryset.filter(Q(device__name__icontains=value)).distinct() diff --git a/netbox_cmdb/netbox_cmdb/views.py b/netbox_cmdb/netbox_cmdb/views.py index 715c793..4a4521f 100644 --- a/netbox_cmdb/netbox_cmdb/views.py +++ b/netbox_cmdb/netbox_cmdb/views.py @@ -11,6 +11,7 @@ ASNFilterSet, BGPPeerGroupFilterSet, BGPSessionFilterSet, + SNMPFilterSet, ) from netbox_cmdb.forms import ( ASNForm, @@ -124,6 +125,7 @@ class BGPPeerGroupView(ObjectView): ## Snmp groups views class SNMPListView(ObjectListView): queryset = SNMP.objects.all() + filterset = SNMPFilterSet table = SNMPTable