diff --git a/netbox_acls/filtersets.py b/netbox_acls/filtersets.py index 8b384fe..7a8e6d0 100644 --- a/netbox_acls/filtersets.py +++ b/netbox_acls/filtersets.py @@ -3,7 +3,7 @@ when filtering the sites list by status or region, for instance. """ import django_filters -from dcim.models import Device, Interface, VirtualChassis +from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis from django.db.models import Q from netbox.filtersets import NetBoxModelFilterSet from virtualization.models import VirtualMachine, VMInterface @@ -22,7 +22,24 @@ class AccessListFilterSet(NetBoxModelFilterSet): """ Define the filter set for the django model AccessList. """ - + region = django_filters.ModelMultipleChoiceFilter( + field_name="device__site__region", + queryset=Region.objects.all(), + to_field_name="id", + label="Region", + ) + site_group = django_filters.ModelMultipleChoiceFilter( + field_name="device__site__group", + queryset=SiteGroup.objects.all(), + to_field_name="id", + label="Site Group", + ) + site = django_filters.ModelMultipleChoiceFilter( + field_name="device__site", + queryset=Site.objects.all(), + to_field_name="id", + label="Site", + ) device = django_filters.ModelMultipleChoiceFilter( field_name="device__name", queryset=Device.objects.all(), @@ -75,6 +92,9 @@ class Meta: "type", "default_action", "comments", + "site", + "site_group", + "region", ) def search(self, queryset, name, value): diff --git a/netbox_acls/forms/filtersets.py b/netbox_acls/forms/filtersets.py index 8784725..33ac9fb 100644 --- a/netbox_acls/forms/filtersets.py +++ b/netbox_acls/forms/filtersets.py @@ -4,6 +4,7 @@ from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis from django import forms +from django.utils.translation import gettext as _ from ipam.models import Prefix from netbox.forms import NetBoxModelFilterSetForm from utilities.forms.fields import ( @@ -14,6 +15,7 @@ from utilities.forms.utils import add_blank_choice from virtualization.models import VirtualMachine, VMInterface + from ..choices import ( ACLActionChoices, ACLAssignmentDirectionChoices, @@ -56,7 +58,7 @@ class AccessListFilterForm(NetBoxModelFilterSetForm): required=False, query_params={"region_id": "$region", "group_id": "$site_group"}, ) - device = DynamicModelChoiceField( + device_id = DynamicModelChoiceField( queryset=Device.objects.all(), query_params={ "region_id": "$region", @@ -64,14 +66,17 @@ class AccessListFilterForm(NetBoxModelFilterSetForm): "site_id": "$site", }, required=False, + label=_("Device",), ) - virtual_machine = DynamicModelChoiceField( + virtual_machine_id = DynamicModelChoiceField( queryset=VirtualMachine.objects.all(), required=False, + label=_("Virtual Machine",) ) - virtual_chassis = DynamicModelChoiceField( + virtual_chassis_id = DynamicModelChoiceField( queryset=VirtualChassis.objects.all(), required=False, + label=_("Virtual Chassis",) ) type = forms.ChoiceField( choices=add_blank_choice(ACLTypeChoices), @@ -92,9 +97,9 @@ class AccessListFilterForm(NetBoxModelFilterSetForm): "region", "site_group", "site", - "device", - "virtual_chassis", - "virtual_machine", + "device_id", + "virtual_chassis_id", + "virtual_machine_id", ), ), ("ACL Details", ("type", "default_action")),