From ce5ddf78731d1d4a6f106433a4baad4fb7dbde8f Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 14 Jun 2023 19:10:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20filter=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/db/fields.py | 4 ++-- apps/common/drf/filters.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/common/db/fields.py b/apps/common/db/fields.py index 3e1b1ac98..b1cdc76d6 100644 --- a/apps/common/db/fields.py +++ b/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 diff --git a/apps/common/drf/filters.py b/apps/common/drf/filters.py index cfdff0a6e..bac14190e 100644 --- a/apps/common/drf/filters.py +++ b/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()