mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 19:52:52 -06:00
23 lines
603 B
Python
23 lines
603 B
Python
import django_filters
|
|
|
|
from .models import Tag
|
|
|
|
__all__ = (
|
|
'TagFilter',
|
|
)
|
|
|
|
|
|
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('field_name', 'tags__slug')
|
|
kwargs.setdefault('to_field_name', 'slug')
|
|
kwargs.setdefault('conjoined', True)
|
|
kwargs.setdefault('queryset', Tag.objects.all())
|
|
|
|
super().__init__(*args, **kwargs)
|