mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-13 16:47:34 -06:00
Revert "Fixes: #18783 Add a tag_id filter for all models which support taggin…"
This reverts commit 9a1d9365cd
.
This commit is contained in:
parent
82b9e4ca26
commit
fe7fb94e44
@ -61,11 +61,6 @@ class MyModelViewSet(...):
|
|||||||
|
|
||||||
The `TagFilter` class is available for all models which support tag assignment (those which inherit from `NetBoxModel` or `TagsMixin`). This filter subclasses django-filter's `ModelMultipleChoiceFilter` to work with NetBox's `TaggedItem` class.
|
The `TagFilter` class is available for all models which support tag assignment (those which inherit from `NetBoxModel` or `TagsMixin`). This filter subclasses django-filter's `ModelMultipleChoiceFilter` to work with NetBox's `TaggedItem` class.
|
||||||
|
|
||||||
This class filters `tags` using the `slug` field. For example:
|
|
||||||
|
|
||||||
`GET /api/dcim/sites/?tag=alpha&tag=bravo`
|
|
||||||
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from django_filters import FilterSet
|
from django_filters import FilterSet
|
||||||
from extras.filters import TagFilter
|
from extras.filters import TagFilter
|
||||||
@ -73,19 +68,3 @@ from extras.filters import TagFilter
|
|||||||
class MyModelFilterSet(FilterSet):
|
class MyModelFilterSet(FilterSet):
|
||||||
tag = TagFilter()
|
tag = TagFilter()
|
||||||
```
|
```
|
||||||
|
|
||||||
### TagIDFilter
|
|
||||||
|
|
||||||
The `TagIDFilter` class is available for all models which support tag assignment (those which inherit from `NetBoxModel` or `TagsMixin`). This filter subclasses django-filter's `ModelMultipleChoiceFilter` to work with NetBox's `TaggedItem` class.
|
|
||||||
|
|
||||||
This class filters `tags` using the `id` field. For example:
|
|
||||||
|
|
||||||
`GET /api/dcim/sites/?tag_id=100&tag_id=200`
|
|
||||||
|
|
||||||
```python
|
|
||||||
from django_filters import FilterSet
|
|
||||||
from extras.filters import TagIDFilter
|
|
||||||
|
|
||||||
class MyModelFilterSet(FilterSet):
|
|
||||||
tag_id = TagIDFilter()
|
|
||||||
```
|
|
||||||
|
@ -4,7 +4,6 @@ from .models import Tag
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'TagFilter',
|
'TagFilter',
|
||||||
'TagIDFilter',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -21,18 +20,3 @@ class TagFilter(django_filters.ModelMultipleChoiceFilter):
|
|||||||
kwargs.setdefault('queryset', Tag.objects.all())
|
kwargs.setdefault('queryset', Tag.objects.all())
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TagIDFilter(django_filters.ModelMultipleChoiceFilter):
|
|
||||||
"""
|
|
||||||
Match on one or more assigned tags. If multiple tags are specified (e.g. ?tag=1&tag=2), the queryset is filtered
|
|
||||||
to objects matching all tags.
|
|
||||||
"""
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
|
|
||||||
kwargs.setdefault('field_name', 'tags__id')
|
|
||||||
kwargs.setdefault('to_field_name', 'id')
|
|
||||||
kwargs.setdefault('conjoined', True)
|
|
||||||
kwargs.setdefault('queryset', Tag.objects.all())
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
@ -11,7 +11,7 @@ from users.models import Group, User
|
|||||||
from utilities.filters import ContentTypeFilter, MultiValueCharFilter, MultiValueNumberFilter
|
from utilities.filters import ContentTypeFilter, MultiValueCharFilter, MultiValueNumberFilter
|
||||||
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
||||||
from .choices import *
|
from .choices import *
|
||||||
from .filters import TagFilter, TagIDFilter
|
from .filters import TagFilter
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -665,7 +665,6 @@ class ConfigTemplateFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
label=_('Data file (ID)'),
|
label=_('Data file (ID)'),
|
||||||
)
|
)
|
||||||
tag = TagFilter()
|
tag = TagFilter()
|
||||||
tag_id = TagIDFilter()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ConfigTemplate
|
model = ConfigTemplate
|
||||||
|
@ -10,7 +10,7 @@ from django.utils.translation import gettext as _
|
|||||||
from core.choices import ObjectChangeActionChoices
|
from core.choices import ObjectChangeActionChoices
|
||||||
from core.models import ObjectChange
|
from core.models import ObjectChange
|
||||||
from extras.choices import CustomFieldFilterLogicChoices
|
from extras.choices import CustomFieldFilterLogicChoices
|
||||||
from extras.filters import TagFilter, TagIDFilter
|
from extras.filters import TagFilter
|
||||||
from extras.models import CustomField, SavedFilter
|
from extras.models import CustomField, SavedFilter
|
||||||
from utilities.constants import (
|
from utilities.constants import (
|
||||||
FILTER_CHAR_BASED_LOOKUP_MAP, FILTER_NEGATION_LOOKUP_MAP, FILTER_TREENODE_NEGATION_LOOKUP_MAP,
|
FILTER_CHAR_BASED_LOOKUP_MAP, FILTER_NEGATION_LOOKUP_MAP, FILTER_TREENODE_NEGATION_LOOKUP_MAP,
|
||||||
@ -286,7 +286,6 @@ class NetBoxModelFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
label=_('Search'),
|
label=_('Search'),
|
||||||
)
|
)
|
||||||
tag = TagFilter()
|
tag = TagFilter()
|
||||||
tag_id = TagIDFilter()
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user