So I have a query…
qry = Query(models.UserList).filter(...)
models.UserList contains a mixin method that will return a count of a related table
So what I would like to do is something like …
qry = qry.order_by(models.UserList.contactCount)
However this produces invalid sql of course.
So how can I do something like
qry.add_column((this.contactCount).label("contactCount"))
this.contactCount is just bad psuedocode, but hopefully you get the point.
I’ve been looking at how to do this for a while, but sqlalchemy doc isnt the easiest thing to find stuff in.
any help appreciated
You can use either a
column_propertyor ahybrid_propertyfor that. For example: