Skip to content

Commit

Permalink
Add dns_name filter on the IP Address page netbox-community#13957
Browse files Browse the repository at this point in the history
  • Loading branch information
kprince28 committed Oct 16, 2023
1 parent 14447be commit 6a06b54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion netbox/ipam/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -738,6 +742,17 @@ def _assigned(self, queryset, name, value):
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(
Expand Down
11 changes: 10 additions & 1 deletion netbox/ipam/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 6a06b54

Please sign in to comment.