views:

12

answers:

2

In django, I have a table of people, each of which has a namefirst and namelast.

I want to do the sql:

select * from names where left(namefirst,1)=left(namelast,1).  

Right now my best effort is

qs=People.objects.extra(select={'db':'select left(namefirst,1)=left(namelast,1)'})

but then if i stick a .filter(db=1) on that it generates an error.

I suppose I could order by db and just cut it off, but I know there is a better way to do this.

A: 

Your extra parameter doesn't look right. You should be using the where parameter (not select):

People.objects.extra(where=['left(namefirst,1)=left(namelast,1)'])
ars
yeah, i was trying to select the thing and then filter on it. I should have just filtered on it directly. thanks!
fastmultiplication
cool, glad it works. :)
ars
A: 

aha, almost had it. I can just directly use "where"

People.objects.extra(where=['left(namelast,1)=left(namefirst,1)'])
fastmultiplication