From 58edf021792783c197e93b8560e9d14c346baef2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Jun 2023 10:27:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20json=20field=20re?= =?UTF-8?q?=20=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/db/fields.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/common/db/fields.py b/apps/common/db/fields.py index 4122aafb4..5b7ee7c5f 100644 --- a/apps/common/db/fields.py +++ b/apps/common/db/fields.py @@ -378,9 +378,16 @@ class RelatedManager: if match == 'ip_in': q = cls.get_ip_in_q(name, val) - elif match in ("exact", "contains", "startswith", "endswith", "regex", "gte", "lte", "gt", "lt"): + elif match in ("exact", "contains", "startswith", "endswith", "gte", "lte", "gt", "lt"): lookup = "{}__{}".format(name, match) q = Q(**{lookup: val}) + elif match == 'regex': + try: + re.compile(val) + lookup = "{}__{}".format(name, match) + q = Q(**{lookup: val}) + except re.error: + q = ~Q() elif match == "not": q = ~Q(**{name: val}) elif match in ['m2m', 'in']: