仅按整个和精确数组过滤 ArrayField?
Filtering ArrayField by entire and exact array only?
我在模型上有一个 slug ArrayField。
如何过滤或仅获取整个精确数组?
我目前正在做这样的事情:
search = f'["a", "b", "c"]'
list = search[2:-2].split("', '")
dict = {}
for n, item in enumerate(list):
dict[f"slug__{n}"] = item
obj = queryset.filter(**dict)
但是,这个 returns 任何 slug 以“a”、“b”和“c”开头的对象。
例如
["a", "b", "c"]
["a", "b", "c", "d"]
["a", "b", "c", "d", "e"]
["a", "b", "c", "123"]
我如何进行过滤或获取以便只有完整且精确的 slug 匹配 returns? IE。 obj
只有 returns 个带有 ["a", "b", "c"]
的对象
要通过精确匹配过滤 ArrayField,您只需将要匹配的列表传递给过滤器
queryset = queryset.filter(slug=["a", "b", "c"])
我在模型上有一个 slug ArrayField。
如何过滤或仅获取整个精确数组?
我目前正在做这样的事情:
search = f'["a", "b", "c"]'
list = search[2:-2].split("', '")
dict = {}
for n, item in enumerate(list):
dict[f"slug__{n}"] = item
obj = queryset.filter(**dict)
但是,这个 returns 任何 slug 以“a”、“b”和“c”开头的对象。 例如
["a", "b", "c"]
["a", "b", "c", "d"]
["a", "b", "c", "d", "e"]
["a", "b", "c", "123"]
我如何进行过滤或获取以便只有完整且精确的 slug 匹配 returns? IE。 obj
只有 returns 个带有 ["a", "b", "c"]
要通过精确匹配过滤 ArrayField,您只需将要匹配的列表传递给过滤器
queryset = queryset.filter(slug=["a", "b", "c"])