I have a class with 'start' and 'finish' attributes which are DateTime
columns. I'm trying to create a hybrid property 'duration' which returns
the delta as a datetime.timedelta object. This is working fine for the
instance attribute, but I can't seem to get it to work for the class
expression.
This is close, and works, except that the clas expression returns an
integer:
@hybrid_property
def duration(self):
if self.finish:
return self.finish - self.start
else:
return timedelta(0)
@duration.expression
def duration(cls):
return func.strftime('%s', func.coalesce(cls.finish, cls.start)) -\
func.strftime('%s', cls.start)
As soon as I try to wrap that to convert it to the python object, I get an
exception:
@duration.expression
def duration(cls):
return timedelta(
func.strftime('%s', func.coalesce(cls.finish, cls.start)) -
func.strftime('%s', cls.start)
)
TypeError: unsupported type for timedelta days component: _BinaryExpression
Is there something I need to do to convert the return value from func() in
order to be able to work with it? Or, is what I'm attempting even possible?
Thanks!
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.