mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Search methods and registration
This commit is contained in:
parent
f30b54dae1
commit
5a92975eab
@ -1112,6 +1112,15 @@ class VLANTranslationPolicyFilterSet(NetBoxModelFilterSet):
|
||||
model = VLANTranslationPolicy
|
||||
fields = ('id', 'name', 'description')
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = (
|
||||
Q(name__icontains=value) |
|
||||
Q(description__icontains=value)
|
||||
)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class VLANTranslationRuleFilterSet(NetBoxModelFilterSet):
|
||||
|
||||
@ -1119,6 +1128,20 @@ class VLANTranslationRuleFilterSet(NetBoxModelFilterSet):
|
||||
model = VLANTranslationRule
|
||||
fields = ('id', 'policy', 'local_vid', 'remote_vid')
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = (
|
||||
Q(policy__name__icontains=value)
|
||||
)
|
||||
try:
|
||||
int_value = int(value.strip())
|
||||
qs_filter |= Q(local_vid=int_value)
|
||||
qs_filter |= Q(remote_vid=int_value)
|
||||
except ValueError:
|
||||
pass
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class ServiceTemplateFilterSet(NetBoxModelFilterSet):
|
||||
port = NumericArrayFilter(
|
||||
|
@ -160,6 +160,27 @@ class VLANGroupIndex(SearchIndex):
|
||||
display_attrs = ('scope_type', 'description')
|
||||
|
||||
|
||||
@register_search
|
||||
class VLANTranslationPolicyIndex(SearchIndex):
|
||||
model = models.VLANTranslationPolicy
|
||||
fields = (
|
||||
('name', 100),
|
||||
('description', 500),
|
||||
)
|
||||
display_attrs = ('description',)
|
||||
|
||||
|
||||
@register_search
|
||||
class VLANTranslationRuleIndex(SearchIndex):
|
||||
model = models.VLANTranslationRule
|
||||
fields = (
|
||||
('policy', 100),
|
||||
('local_vid', 200),
|
||||
('remote_vid', 200),
|
||||
)
|
||||
display_attrs = ('policy', 'local_vid', 'remote_vid')
|
||||
|
||||
|
||||
@register_search
|
||||
class VRFIndex(SearchIndex):
|
||||
model = models.VRF
|
||||
|
Loading…
Reference in New Issue
Block a user