Django uses LIKE in an inappropriate way?

I am trying to do the following

from core.models import *
q1 = MessageRecipient.objects.filter(message__subject__icontains="Enfim")

      

Generating the following sentence WHERE

:

WHERE `message`.`subject` LIKE %Enfim%

      

enter image description here

Look at a similar operator.

Django does not use quotation. Am I missing something? I bet you do. Because this is a commonly used function. Someone realized that this was a mistake. What's happening?

+3


source to share


1 answer


If you look at the __str__()

object method Query

at https://github.com/django/django/blob/master/django/db/models/sql/query.py you will see the following warning in the docstring:

The parameter values ​​are not necessarily correct, as they are executed by the database interface at runtime.



Don't worry about it, it doesn't matter, it looks like this message! This is not a bug, so you just need to think about what you are using .query

for. This is good for a debug point or pickle if you want to recreate a set of queries with actual results later. This is not something that you can pass directly to your database.

+2


source







All Articles