mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
Add dns_name filter on the IP Address page #13957
This commit is contained in:
parent
14447befb9
commit
6a06b54348
@ -618,10 +618,14 @@ class IPAddressFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
||||
role = django_filters.MultipleChoiceFilter(
|
||||
choices=IPAddressRoleChoices
|
||||
)
|
||||
dns_name = MultiValueCharFilter(
|
||||
method='search_by_dns',
|
||||
label=_('DNS Name'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = IPAddress
|
||||
fields = ['id', 'dns_name', 'description']
|
||||
fields = ['id', 'description']
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
@ -738,6 +742,17 @@ class IPAddressFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
||||
assigned_object_id__isnull=True
|
||||
)
|
||||
|
||||
def search_by_dns(self, queryset, name, value):
|
||||
if not value:
|
||||
return queryset
|
||||
|
||||
normalized_value = str(value[0]).lower()
|
||||
|
||||
if normalized_value in ('none', 'null'):
|
||||
return queryset.filter(dns_name='')
|
||||
|
||||
return queryset.filter(dns_name__in=value)
|
||||
|
||||
|
||||
class FHRPGroupFilterSet(NetBoxModelFilterSet):
|
||||
protocol = django_filters.MultipleChoiceFilter(
|
||||
|
@ -295,7 +295,7 @@ class IPAddressFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
model = IPAddress
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'tag')),
|
||||
(_('Attributes'), ('parent', 'family', 'status', 'role', 'mask_length', 'assigned_to_interface')),
|
||||
(_('Attributes'), ('parent', 'family', 'status', 'role', 'mask_length', 'assigned_to_interface', 'dns_name')),
|
||||
(_('VRF'), ('vrf_id', 'present_in_vrf_id')),
|
||||
(_('Tenant'), ('tenant_group_id', 'tenant_id')),
|
||||
(_('Device/VM'), ('device_id', 'virtual_machine_id')),
|
||||
@ -357,6 +357,15 @@ class IPAddressFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||
)
|
||||
)
|
||||
dns_name = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'DNS Name',
|
||||
}
|
||||
),
|
||||
label='DNS Name'
|
||||
)
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user