Ok so far I have this:
expressions = []
for tag in tag_list:
expressions += session.query(Document).filter(Tag.tag==tag)
documents =
session.query(Document).join(Document.tags).filter(and_(*expressions))
Doesn't work but it's progress! :)
On Mar 18, 2:37 pm, Stodge sto...@gmail.com
Now we're getting somewhere:
expressions = []
for tag in tag_list:
expressions += [Tag.tag==tag]
documents =
session.query(Document).join(Document.tags).filter(and_(*expressions))
Thanks to a Storm example I found. :)
On Mar 19, 8:12 am, Stodge sto...@gmail.com wrote:
Ok so far I have
select document.* from document join tags on document.id=tags.document_id
where tags.tag='foo' and tags.tag='bar' and tags.tag=
am I missing something ? that would return no rows in most cases.
if you want to find documents that have an exact list of tags, you'd have to do
something like
Thanks. That doesn't quite work. Based on my data, the following
should (and does) work because it only returns document id=1, which
only has these two tags:
tag_list = ['my document', 'source code']
session.query(Document).\
filter(Document.tags.any(Tag.tag.in_([t for t in tag_list]))).\
Getting closer. Maybe something like this:
q1 = session.query(Document).join(Document.tags).filter(Tag.tag=='my
document')
q2 =
session.query(Document).join(Document.tags).filter(Tag.tag=='source
code')
q3 = q1.intersect(q2)
q4 = session.query(Document).filter(Document.title=='Source Code')
print
Stodge wrote:
Thanks. That doesn't quite work. Based on my data, the following
should (and does) work because it only returns document id=1, which
only has these two tags:
tag_list = ['my document', 'source code']
session.query(Document).\
filter(Document.tags.any(Tag.tag.in_([t for t
Thanks! That worked beautifully. :)
On Mar 19, 11:18 am, Conor conor.edward.da...@gmail.com wrote:
Stodge wrote:
Thanks. That doesn't quite work. Based on my data, the following
should (and does) work because it only returns document id=1, which
only has these two tags:
tag_list = ['my
Thanks that worked beautifully.
On a similar note, how would I match documents with only the tags that
I specify in the list? My naive attempt is:
for tag in tag_list:
session.query(Document).join(Document.tags).filter_by(tag=tag)
But that doesn't work.
On Mar 15, 10:54 am, Michael Bayer
Thanks. I wrote the error message from memory, the exact wording is:
session.query(Document).filter(Document.tags.in_(tag_list))
Traceback (most recent call last):
File stdin, line 1, in module
File /usr/lib/python2.6/site-packages/sqlalchemy/sql/
expression.py, line 1274, in in_
return