Hello,
I am trying to use onupdate context sensitive function and I came with the
following problem.
I have a simple model
class Email(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
email_number = db.Column(db.Integer, nullable=False)
body = db.Column(db.Integer, nullable=False)
updated = db.Column(db.TIMESTAMP, server_default=db.func.now(),
onupdate=on_update, nullable)
Where the on_update function (in Email.updated(onupdate=....) is:
def on_update(context):
if 'body' in context.current_parameters:
now = datetime.datetime.now()
ts = context.current_parameters['updated'] = "{}-{}-{}
{}:{}:{}.{}".format(
now.year, now.month, now.day,
now.hour, now.minute, now.second,
now.microsecond,
)
return ts
else:
ts = context.current_parameters['updated']
if ts is None:
now = datetime.datetime.now()
ts = context.current_parameters['updated'] = "{}-{}-{}
{}:{}:{}.{}".format(
now.year, now.month, now.day,
now.hour, now.minute, now.second,
now.microsecond,
)
return ts
The reason for that is that I want to updated the Email.update only when
the Email.body has changed and not when Email.email_number is changing. But
when I change only the email_number the context contains:
>>> context.current_parameters['updated']
None
and not the current value updated field on the instance.
Any ideas how to implement the logic I want?
Best regards,
Marcin
--
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.