feat: myjsonfield优化

This commit is contained in:
caoqianming 2025-05-07 10:25:07 +08:00
parent 2128b4e847
commit cc12d80c92
1 changed files with 5 additions and 2 deletions

View File

@ -3,13 +3,16 @@ from django_filters import rest_framework as filters
class MyJsonListFilter(filters.CharFilter):
def filter(self, qs, value):
if value in ['all', '']:
return qs
elif ',' in value:
value_l = value.split(',')
qsx = qs.none()
for i in value_l:
qsx = qsx | qs.filter(tags__contains=i)
kv = {f"{self.field_name}__contains": i}
qsx = qsx | qs.filter(**kv)
return qsx
else:
return qs.filter(tags__contains=value)
kv = {f"{self.field_name}__contains": value}
return qs.filter(**kv)