Skip to content

Plugin filter searching not working - NetboxModelFilterSet #9923

Answered by jeremystretch
cslingerland asked this question in Q&A
Discussion options

You must be logged in to vote

To enable general searching, you need to override NetBoxModelFilterSet's search() method and define the fields to search on. By default this returns the entire queryset. Here's an example from the Site model:

def search(self, queryset, name, value):
if not value.strip():
return queryset
qs_filter = (
Q(name__icontains=value) |
Q(facility__icontains=value) |
Q(description__icontains=value) |
Q(physical_address__icontains=value) |
Q(shipping_address__icontains=value) |
Q(comments__icontains=value)
)
try:
qs_filter |= Q(asns__asn=int(value.strip()))
except V…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cslingerland
Comment options

Answer selected by cslingerland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants