mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-19 10:08:44 -06:00
* Closes #17793: Introduce a REST API endpoint for tagged objects * Add missing object_id filter to TaggedItemFilterSet
This commit is contained in:
@@ -31,6 +31,7 @@ __all__ = (
|
||||
'SavedFilterFilterSet',
|
||||
'ScriptFilterSet',
|
||||
'TagFilterSet',
|
||||
'TaggedItemFilterSet',
|
||||
'WebhookFilterSet',
|
||||
)
|
||||
|
||||
@@ -492,6 +493,41 @@ class TagFilterSet(ChangeLoggedModelFilterSet):
|
||||
)
|
||||
|
||||
|
||||
class TaggedItemFilterSet(BaseFilterSet):
|
||||
q = django_filters.CharFilter(
|
||||
method='search',
|
||||
label=_('Search'),
|
||||
)
|
||||
object_type = ContentTypeFilter(
|
||||
field_name='content_type'
|
||||
)
|
||||
object_type_id = django_filters.ModelMultipleChoiceFilter(
|
||||
queryset=ContentType.objects.all(),
|
||||
field_name='content_type_id'
|
||||
)
|
||||
tag_id = django_filters.ModelMultipleChoiceFilter(
|
||||
queryset=Tag.objects.all()
|
||||
)
|
||||
tag = django_filters.ModelMultipleChoiceFilter(
|
||||
field_name='tag__slug',
|
||||
queryset=Tag.objects.all(),
|
||||
to_field_name='slug',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = TaggedItem
|
||||
fields = ('id', 'object_id')
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
return queryset
|
||||
return queryset.filter(
|
||||
Q(tag__name__icontains=value) |
|
||||
Q(tag__slug__icontains=value) |
|
||||
Q(tag__description__icontains=value)
|
||||
)
|
||||
|
||||
|
||||
class ConfigContextFilterSet(ChangeLoggedModelFilterSet):
|
||||
q = django_filters.CharFilter(
|
||||
method='search',
|
||||
|
||||
Reference in New Issue
Block a user