From c42c520c6610b4dccdb70100892753e47104b374 Mon Sep 17 00:00:00 2001 From: zhaozhengran <97390483@qq.com> Date: Fri, 10 Jul 2020 16:13:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(get=20user):=20=E4=BF=AE=E5=A4=8D=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5=E6=90=9C=E7=B4=A2=E6=8A=A5?= =?UTF-8?q?=E9=94=99(=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=BC=80=E5=A4=B4=E4=B8=BA=E6=95=B0=E5=AD=97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- siteapi/v1/views/user.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/siteapi/v1/views/user.py b/siteapi/v1/views/user.py index e9bde496d..bfb6a6602 100644 --- a/siteapi/v1/views/user.py +++ b/siteapi/v1/views/user.py @@ -61,6 +61,7 @@ def get_permissions(self): # pylint: disable=too-many-locals # pylint: disable=too-many-branches + # pylint: disable=too-many-statements def get_queryset(self): ''' return queryset for list [GET] @@ -162,11 +163,14 @@ def get_queryset(self): # 获取 query string 中自定义字段(*__custom) # 支持 *__(lte, gte, lt, gt 等)__custom 形式,需进行范围搜索的字段在存储时保证传入的为string - suffix = '__custom' + suffixes = ['__lte__custom', '__lt__custom', '__gte__custom', '__gt__custom', '__custom'] for key, value in self.request.query_params.items(): - if key.endswith(suffix): - queryset = queryset.filter(**{'custom_user__data__' + key[:-1 * len(suffix)]: value}) - + for suffix in suffixes: + if key.endswith(suffix): + _key = 'custom_user__data__"{custom_field}"{suffix}'.format(custom_field=key[:-1 * len(suffix)], + suffix=suffix[:-8]) + queryset = queryset.filter(**{_key: value}) + break # 支持自定义排序 # QueryString 中格式为 '&sort=field1 ... fieldn' _sort = self.request.query_params.get('sort')