Hi there,

I'd like to be able to run sorted() on a list of model objects without 
class-specific code which sorts based on what's specified 
in __mapper_args__['order_by'].

To do that, I would add __lt__(), __le__(), __gt__(), and/or __ge__() to 
the declarative base class, which try to get the order_by specification 
from the mapper and behave accordingly.

My problem is now to find the correct programmatical way to get the class 
attribute name and whether to sort reversed or not.

With instance.__mapper__.order_by, I can get the list of expressions, from 
which I can extract the attribute name, if it's just a plain attribute. But 
when its order_by=[desc(column)], I only get 
an sqlalchemy.sql.expression._UnaryExpression from which I can't figure out 
the correct way to get what I need (....elements would contain the column, 
but I can't find the place where I see that it's descending order).

Can someone help me on this?

Regards,
Moritz

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to