本文介绍了sql“LIKE”相当于django查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在django中相当于这个SQL语句是什么?

  SELECT * FROM table_name WHERE string LIKE pattern; 

如何在django中实现?我试过

  result = table.objects.filter(string in string)
/ pre>

但是没有工作。我该如何实现?

解决方案

使用或:

  result = table.objects.filter(string__contains ='pattern')


What is the equivalent of this SQL statement in django?

SELECT * FROM table_name WHERE string LIKE pattern;

How do I implement this in django? I tried

result = table.objects.filter( pattern in string )

But that did not work. How do i implement this?

解决方案

Use contains or icontains:

result = table.objects.filter(string__contains='pattern')

这篇关于sql“LIKE”相当于django查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:59
查看更多