ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.66k stars 245 forks source link

callback on record insert, delete and update #584

Open sugizo opened 3 years ago

sugizo commented 3 years ago

Objective

before insert table can execute python function to convert data e.g. user insert Field intervals in list [2, 2, 1, 2, 2, 2, 1] then base on list above automatically convert and insert into Field intervals_name with [W, W, H, W, W, W, H] on the same table

or

after insert table can send email to user, base on field email stored on another table e.g.

def after_insert_nav(f, id):
    query_account_0 = (db.account.product == f['product'] )
    rows_account = db(query_account_0).iterselect()
    for row_account in rows_account:
        if row_account.investor.notification:
            mail_to = row_account.investor.email
            subject = 'NAV %s' % row_account.product.name
            messages = response.render('templates/mail/nav.html', 
                                               dict(row = row_account, row_nav = row_nav) )
            attachments = ''
            insert_mail_queue(mail_to, subject, messages, attachments)

question

is it possible to use callback on record insert, delete and update in pony ?

ref http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update

n.b. objective above can be achieve in pydal

thanks

jgirardet commented 3 years ago

https://docs.ponyorm.org/api_reference.html#entity-hooks