jack User query filter_by name Jack first jack User query filter User

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
>>> jack = User.query.filter_by(name=u'Jack').first()
>>> jack = User.query.filter(User.name==u'Jack').first()
>>> jack
<<< <User u'Jack'>
>>> Message.query.filter(Message.recipients.contains(jack))
<<< <sqlalchemy.orm.query.Query object at 0x87b796c>
>>> list(_)
<<<
[<Message: from <User u'Edvard'> to <User u'Jack'>, <User u'Mary'> (subj: u'Hey all')>,
<Message: from <User u'Mary'> to <User u'Jack'> (subj: u'Hi')>]
>>> Message.query.filter(Message.author==jack).first()
<<< <Message: from <User u'Jack'> to <User u'Edvard'>, <User u'Mary'> (subj: u'The first')>