In Python, DJANGO does the station, in the usual case, need to use the OrM query method, such as object.filter (tag__contains= ' keywords ') ....
In this case, if you trace the SQL statement, you will find that the SQL statement will generate a select .... like Bianry '%keywords% ', if this is the case, it will be problematic in some cases, which means that the data you are querying may be less than you expect.
If you use raw SQL to check the total number of select count (*) from table where the like '%keywords% ' gets a lot more data than you can get with ORM using the above method, the problem lies in the resulting condition problem.
The Django instructions were later queried, if the ORM statement became: object.filter (tag__icontains= ' keywords ') .... Just fine.
Note the difference between contains and icontains. Later from the Django official website to find out the description:
Program code
Operators = {
' exact ': ' =%s ',
' Iexact ': ' Like%s ',
' contains ': ' Like BINARY%s ',
' Icontains ': ' Like%s ',
' Regex ': ' REGEXP BINARY%s ',
' Iregex ': ' REGEXP%s ',
' GT ': ' >%s ',
' GTE ': ' >=%s ',
' LT ': ' <%s ',
' LTE ': ' <=%s ',
' StartsWith ': ' Like BINARY%s ',
' EndsWith ': ' Like BINARY%s ',
' Istartswith ': ' Like%s ',
' Iendswith ': ' Like%s ',
}
Refer to the instructions, you can write your own statement.
Django Object filter query [go]