Browse Source

perf: 优化 filter name

pull/10715/head
ibuler 1 year ago
parent
commit
ce5ddf7873
  1. 4
      apps/common/db/fields.py
  2. 2
      apps/common/drf/filters.py

4
apps/common/db/fields.py

@ -295,7 +295,7 @@ class RelatedManager:
self.instance.__dict__[self.field.name] = value
@classmethod
def _get_filter_q(cls, value, to_model):
def get_to_filter_q(cls, value, to_model):
"""
这个是 instance 去查找 to_model queryset Q
:param value:
@ -320,7 +320,7 @@ class RelatedManager:
queryset = to_model.get_queryset()
else:
queryset = to_model.objects.all()
q = cls._get_filter_q(value, to_model)
q = cls.get_to_filter_q(value, to_model)
return queryset.filter(q).distinct()
@staticmethod

2
apps/common/drf/filters.py

@ -214,5 +214,5 @@ class AttrRulesFilterBackend(filters.BaseFilterBackend):
raise ValidationError({'attr_rules': 'attr_rules should be json'})
logging.debug('attr_rules: %s', attr_rules)
q = RelatedManager.get_filter_q(attr_rules, queryset.model)
q = RelatedManager.get_to_filter_q(attr_rules, queryset.model)
return queryset.filter(q).distinct()

Loading…
Cancel
Save