Take a look at the [1][2]'operators' attribute of the backend's
DatabaseWrapper class and the [3]lookup_cast() method of
the 'ops' attribute (usually an instance of a backend-provided
subclass of DatabaseOperations).
Both are [4]used for building that kind of queries.
HTH,
--
Ramiro Morales | http://rmorales.net
1. http://code.djangoproject.com/browser/django/trunk/django/db/backends/dummy/base.py?rev=11596#L39
2. http://code.djangoproject.com/browser/django/trunk/django/db/backends/sqlite3/base.py?rev=11596#L129
3. http://code.djangoproject.com/browser/django/trunk/django/db/backends/__init__.py?rev=11596#L229
4. http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/where.py?rev=11596#L166