[Solved]-Django query how to write: WHERE field LIKE '10__8__0__'?


You can do this with django-like:


Also I created a related ticket on the Django project site



The easiest way to do the search you intend to do is by regular expression:



My solution is possibly much slower than LIKE. The problem though is that the django ORM does not allow easy access to LIKE. It’d be easiest if startswith or endswith were sufficient for your purposes.



You can use extra to do this:

MyModel.objects.extra(where=["column_name LIKE '%10%"])

Note that column_name is the column name in the database, rather than the field name in your Django model. In many cases, the field name and column name will be the same, but if they differ, take care to use the column name.


In SQL, you can query it like:

WHERE field LIKE '10??8??0??'

Try that in your Django filter.


Leave a comment