mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 12:22:23 -06:00
Fixes #2558: Filter on all tags when multiple are passed
This commit is contained in:
@@ -5,6 +5,7 @@ import itertools
|
||||
import django_filters
|
||||
from django import forms
|
||||
from django.utils.encoding import force_text
|
||||
from taggit.models import Tag
|
||||
|
||||
|
||||
#
|
||||
@@ -68,3 +69,18 @@ class NullableModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
stripped_value = value
|
||||
super(NullableModelMultipleChoiceField, self).clean(stripped_value)
|
||||
return value
|
||||
|
||||
|
||||
class TagFilter(django_filters.ModelMultipleChoiceFilter):
|
||||
"""
|
||||
Match on one or more assigned tags. If multiple tags are specified (e.g. ?tag=foo&tag=bar), the queryset is filtered
|
||||
to objects matching all tags.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
kwargs.setdefault('name', 'tags__slug')
|
||||
kwargs.setdefault('to_field_name', 'slug')
|
||||
kwargs.setdefault('conjoined', True)
|
||||
kwargs.setdefault('queryset', Tag.objects.all())
|
||||
|
||||
super(TagFilter, self).__init__(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user