作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做一个搜索功能:我使用GodX
在用户管理中注册我的用户名,当我搜索godx
作为用户名关键字后,我可以得到 GodX
对象。
目前我只能执行以下操作:
from django.contrib.auth.models import User
user = user.objects.get(username="godx")
# I hope I can get `GodX` object but the method is unavailable.
我该怎么办?
最佳答案
我自己找到答案!
根据 django 文档中的这些链接:
如果我使用iexact
:
>>> Blog.objects.get(name__iexact="beatles blog")
它将匹配标题为“Beatles Blog”、“beatles blog”甚至“BeAtlES blOG”的博客。
以及 SQL 等效项:
SELECT ... WHERE name ILIKE 'beatles blog';
所以,我可以得到我所期望的。
关于python - 如何在 Django 中搜索 CharField?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33117542/
我是一名优秀的程序员,十分优秀!