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)=le开发者_如何学编程ft(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.
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)'])
精彩评论