Skip to content

Commit

Permalink
adds assigned bool for ip address API #13151
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi1693 committed Jul 29, 2023
1 parent 006c353 commit f3fe05b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions netbox/ipam/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ class IPAddressFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
method='_assigned_to_interface',
label=_('Is assigned to an interface'),
)
assigned = django_filters.BooleanFilter(
method='_assigned',
label=_('Is assigned'),
)
status = django_filters.MultipleChoiceFilter(
choices=IPAddressStatusChoices,
null_value=None
Expand Down Expand Up @@ -706,6 +710,18 @@ def _assigned_to_interface(self, queryset, name, value):
assigned_object_id__isnull=False
)

def _assigned(self, queryset, name, value):
if value:
return queryset.exclude(
assigned_object_type__isnull=True,
assigned_object_id__isnull=True
)
else:
return queryset.filter(
assigned_object_type__isnull=True,
assigned_object_id__isnull=True
)


class FHRPGroupFilterSet(NetBoxModelFilterSet):
protocol = django_filters.MultipleChoiceFilter(
Expand Down

0 comments on commit f3fe05b

Please sign in to comment.