[英]Using .filter in Django to see if title contains a certain string?
My code is:我的代码是:
posts = Listing.objects.filter(title=q, is_live=1)
I need the equivalent of:我需要相当于:
posts = Listing.objects.filter(q in title, is_live=1)
How can I just determine if a certain bit of text exists and isn't exactly equal to the query?我如何才能确定某个文本是否存在并且不完全等于查询?
Try this:尝试这个:
posts = Listing.objects.filter(title__contains=q, is_live=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.