I have a simple query with a group_by and count(), and I'd like to
pass this to webhelpers.paginate for display:
def referrers(self):
s = select([m.hit_table.c.id, m.hit_table.c.referer, func.count
(m.Hit.referer).label('count')],
from_obj = [m.hit_table],
group_by = [m.Hit.referer],
order_by = 'count desc')
query = meta.Session.query(m.Hit).from_statement(s)
c.paginator = paginate.Page(
query,
page = int(request.params.get('page', 1)),
items_per_page = 50,
)
return render('/derived/hits/referrer_list.html')
The sql generated by this is fine:
SELECT hit.id AS hit_id, hit.referer AS hit_referer, count
(hit.referer) AS count
FROM hit GROUP BY hit.referer ORDER BY count desc
and the results are correct.
When I run this, I get:
Module sqlalchemy.orm.query:1956 in setup_context
<< context.froms.append(self.selectable)
if context.order_by is False and self.mapper.order_by:
context.order_by = self.mapper.order_by
>> if context.order_by is False and self.mapper.order_by:
AttributeError: 'QueryContext' object has no attribute 'order_by'
This evidently has nothing to do with the query's order_by clause
since I get the same error if I remove it. If I execute the query and
pass the results to paginate:
results = query.all()
c.paginator = paginate.Page(
results,
page = int(request.params.get('page', 1)),
items_per_page = 50,
)
I get:
AttributeError: 'Hit' object has no attribute 'count'
Which I guess makes sense, since I don't have that defined in my
class.
What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---