根据此文档 ,我应该可以在我的Django对象变量上使用queryset'_contains'来过滤我的结果
但是当我实现这个代码时:
cookbooks = Books.objects.filter (category_contains = 'cooking')
我收到以下错误:
Cannot resolve keyword 'category_contains' into field. Choices are: category, adder, date etc.
这是为什么发生? 我还看到了这个StackOverflow问题 ,有人解释说只是使用变量category意味着category_exact 。 但是如果我编写category_exact我会得到一个类似的错误。
I should be able to use the queryset '_contains' on my Django object variables to filter my results, according to this documentation
But when I implement this code:
cookbooks = Books.objects.filter (category_contains = 'cooking')
I get the following error:
Cannot resolve keyword 'category_contains' into field. Choices are: category, adder, date etc.
Why is this happening? I also saw this StackOverflow question where someone explains that just using variable category implies category_exact. But if I write category_exact I get a similar error.
最满意答案
您需要使用双下划线__而不是单个下划线_ 。
You need to use a double underscore __ not a single underscore _.
更多推荐
发布评论