iqmaker
iqmaker

Reputation: 2262

Django filter and MySQL (SUBSTRING, LENGTH)

please tell me, how i can make query into database (mysql), with Django models filters. I want create select query like:

    SELECT word FROM core_dictionary WHERE LENGTH(word)=8 AND SUBSTRING(word,1,1)='А';

Sorry for my English.

Upvotes: 1

Views: 1102

Answers (1)

iqmaker
iqmaker

Reputation: 2262

I found a way to solve this problem only by using the "extra":

    d = Dictionary.objects.values_list('word').extra( where=['LENGTH(word)=%s'%(int(wordlen)*2), 'SUBSTRING(word,1,1)="%s"' % startchar] )   

But i think is not good way....

Upvotes: 1

Related Questions