Hi,
Ok, I am doing a "standard" tags thingee which is many-to-many. I want
to to a query so that I get the main records which have all the named
keywords. To use webpage paging efficiently, I need to get a count()
of the records. This does not seem to work the way I am doing it.
Also, I don't think ranges are working, either, for this query (e.g., .
[3:5]).
The query:
taglist = ['science']
tagcount = 1
page_q = SES.query(Quote)
quotes_q = page_q.join(Quote.tags).filter(Tag.tagword.in_(taglist)).\
group_by(Quote.id).having(func.count(Quote.id) ==
tagcount)
n = quotes_q.count()
print "count n=", n
USUALLY puts out a "1", or "None" (both of which are incorrect).
NOTE:
qrecs = quotes_q.all() works!
3 tables: the relation table, plus two classes (irrelevant stuff
removed):
quote_tag = Table('quote_tag', meta.metadata,
Column('quote_id', Integer, ForeignKey
('quote.id')),
Column('tag_id', Integer, ForeignKey('tag.id'))
)
class Quote(Base):
__tablename__ = "quote"
id = Column(Integer, primary_key=True)
date_create = Column(DateTime)
qbody = Column(UnicodeText)
tags = relation("Tag", secondary=quote_tag, backref='quote')
class Tag(Base):
__tablename__ = "tag"
id = Column(Integer, primary_key=True)
tagword = Column(Unicode(20), nullable=False, unique=True)
Any ideas what I am doing wrong? (Also, I am obviously a SQL
dyslexic!)
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---