Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将如何进行以下查询?
SELECT * FROM title WHERE id LIKE '12345%'
我目前拥有的是:
Title.objects.get(id='12345')
这显然不这样做LIKE%(并且icontains两者都这样做)。这里正确的查询是什么?
LIKE%
icontains
Title.objects.filter(id__startswith='12345')
https://docs.djangoproject.com/en/dev/ref/models/querysets/
您可以这样做,您想要过滤表的字符串code在哪里。startswith
code
startswith
code = '12345' 在此处输入代码Title.objects.extra(where=["%s LIKE id||'%%'"], params=[code])