Discussion:
How do I import in_
mmblnfrn
2009-05-16 14:14:40 UTC
Permalink
Hi,

I've problems to write a filter function:

user_q = meta.Session.query(model.BPUser)
user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
model.BPUser.state.in_([0,1]))).first()



I've tried to load the in_ function by
from sqlalchemy import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_
from sqlalchemy.sql import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_
from sqlalchemy.sql.expression import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_


Any hints ?

vbr
Matt
Wichert Akkerman
2009-05-16 16:40:41 UTC
Permalink
Post by mmblnfrn
Hi,
user_q = meta.Session.query(model.BPUser)
user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
model.BPUser.state.in_([0,1]))).first()
in_ is a method on the column instance, there is no need to import it.

Wichert.
--
Wichert Akkerman <wichert-***@public.gmane.org> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
Ben Bangert
2009-05-16 17:44:02 UTC
Permalink
Post by mmblnfrn
user_q = meta.Session.query(model.BPUser)
user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
model.BPUser.state.in_([0,1]))).first()
Additionally,there's no reason to do the string sub like that, this
should be fine:

user = user_q.filter(and_(model.BPUser.name==username, \

model.BPUser.state.in_([0,1]))).first()

Or if you have some condition where username might not be the right
type, str() it.

Cheers,
Ben

Loading...