perf: 修改标签的搜索

pull/12379/head^2
ibuler 2023-12-20 10:52:02 +08:00 committed by Bryan
parent 9b2b71dddc
commit ac5991fc43
2 changed files with 3 additions and 2 deletions

View File

@ -223,7 +223,7 @@ class LabelFilterBackend(filters.BaseFilterBackend):
return queryset
model = queryset.model
labeled_resource_cls = model.labels.field.related_model
labeled_resource_cls = model._labels.field.related_model
app_label = model._meta.app_label
model_name = model._meta.model_name

View File

@ -5,6 +5,7 @@ class LabeledResourceType(LazyObject):
@staticmethod
def get_res_types():
from rbac.models import ContentType
from .mixins import LabeledMixin
content_types = ContentType.objects.all()
ids = []
for ct in content_types:
@ -13,7 +14,7 @@ class LabeledResourceType(LazyObject):
continue
if model_cls._meta.parents:
continue
if 'labels' in model_cls._meta._forward_fields_map.keys():
if issubclass(model_cls, LabeledMixin):
ids.append(ct.id)
return ContentType.objects.filter(id__in=ids)