为什么django queryset不包含适合我的工作?(Why doesn't the django queryset contains work for me?)

编程入门 行业动态 更新时间:2024-10-19 23:44:48
为什么django queryset不包含适合我的工作?(Why doesn't the django queryset contains work for me?)

根据此文档 ,我应该可以在我的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 _.

更多推荐

本文发布于:2023-08-04 14:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不包含   适合   工作   django   queryset

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!