ORM extensions for filtering. These are all automatically added for the
appropriate field types when
django_mysql is in your
Note that lookups specific to included
model fields are documented with the field, rather
Case-sensitive String Comparison#
MySQL string comparison has a case-sensitivity dependent on the collation of
your tables/columns, as the Django manual describes.
However, it is possible to query in a case-sensitive manner even when your data
is not stored with a case-sensitive collation, using the
The following lookup adds that capability to the ORM for
Exact, case-sensitive match for character columns, no matter the underlying collation:
>>> Author.objects.filter(name__case_exact="dickens")  >>> Author.objects.filter(name__case_exact="Dickens") [<Author: Dickens>]
MySQL implements the Soundex algorithm with its
allowing you to find words sounding similar to each other (in
English only, regrettably). These lookups allow you to use that function in the
ORM and are added for
Match a given soundex string:
>>> Author.objects.filter(name__soundex="R163") [<Author: Robert>, <Author: Rupert>]
SELECT ... WHERE SOUNDEX(`name`) = 'R163'
SOUNDEX of the given string:
>>> Author.objects.filter(name__sounds_like="Robert") [<Author: Robert>, <Author: Rupert>]
SELECT ... WHERE `name` SOUNDS LIKE 'Robert'