Django filter and MySQL (SUBSTRING, LENGTH)

1.1k views Asked by At

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.

1

There are 1 answers

1
iqmaker On BEST ANSWER

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....