On Feb 16, 2008 7:30 AM, Thomas Wittek <[EMAIL PROTECTED]> wrote: > > Hi! > > I'm trying to filter my data by some date calculations. > In detail, I want to filter out messages that have been marked as > "deleted" more than 30 days ago. > > In a query I could do it like this: > > threshold = datetime.now() - datetime.timedelta(30) > return Message.query().filter(Message.deleted > threshold).all() > > But how can I do it in a relation() that returns all deleted messages? > I'd have to calculate the threshold on every call to the relation or > I'd have to create a query that will do the calculation in SQL. > For both options I don't know how I could accomplish it. > > messages_deleted=relation( > Message, > primaryjoin=and_(<conditions to create the relation>, > message_table.c.deleted > ????), > ), > > Any ideas? interesting question. I know it can be done with the function sql method, but since ansi and rdbms are exclusive of each others the actual portable code will be a mess.
in mysql u could get away with something like this. >>> from sqlalchemy.sql import func func.datediff(bindparam('now',bindparam('before')) ^^^ not tested > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---