perf: 修改 platform 搜索

pull/9234/head
ibuler 2 years ago
parent 0c2a5bc44a
commit 7ca2fdca89

@ -31,6 +31,7 @@ __all__ = [
class AssetFilterSet(BaseFilterSet):
type = django_filters.CharFilter(field_name="platform__type", lookup_expr="exact")
category = django_filters.CharFilter(field_name="platform__category", lookup_expr="exact")
platform = django_filters.CharFilter(method='filter_platform')
class Meta:
model = Asset
@ -39,6 +40,13 @@ class AssetFilterSet(BaseFilterSet):
"type", "category", "platform"
]
@staticmethod
def filter_platform(queryset, name, value):
if value.isdigit():
return queryset.filter(platform_id=value)
else:
return queryset.filter(platform__name=value)
class AssetViewSet(SuggestionMixin, NodeFilterMixin, OrgBulkModelViewSet):
"""

Loading…
Cancel
Save