Django/MySQL - __istartswith not producing case-insensitive query.
Posted
by TheLizardKing
on Stack Overflow
See other posts from Stack Overflow
or by TheLizardKing
Published on 2010-04-09T20:22:48Z
Indexed on
2010/04/09
20:53 UTC
Read the original article
Hit count: 442
I make use of generic views and I am attempting to query my MySQL db (utf8_bin collation) in a case insensitive manor to try to find all my song titles that start with a particular letter.
view.py
def tracks_by_title(request, starts_with):
return object_list(
request,
queryset = Track.objects.filter(title__istartswith=starts_with),
template_name = 'tlkmusic_base/titles_list.html',
template_object_name = 'tracks',
paginate_by = 25,
)
and my
urls.py
urlpatterns = patterns('tlkmusic.apps.tlkmusic_base.views',
(r'^titles/(?P<starts_with>\w)/$', tracks_by_title),
)
the query it produces according to the django debug toolbar is:
SELECT `tracks`.`id`, `tracks`.`url`, `tracks`.`artist`, `tracks`.`album`, `tracks`.`genre`, `tracks`.`year`, `tracks`.`title`, `tracks`.`comment`, `tracks`.`tracknumber`, `tracks`.`discnumber`, `tracks`.`bitrate`, `tracks`.`length`, `tracks`.`samplerate`, `tracks`.`filesize`, `tracks`.`createdate`, `tracks`.`modifydate` FROM `tracks` WHERE `tracks`.`title` LIKE a% LIMIT 1
specifically this line:
WHERE `tracks`.`title` LIKE a% LIMIT 1
Why is it not ILIKE which is what I was expecting by using __istartswith?
I am using Django 1.1.1 on Ubuntu.
© Stack Overflow or respective owner