Created
December 31, 2021 15:22
-
-
Save thorin-schiffer/2cf54594c9e506130675a2656dba2abc to your computer and use it in GitHub Desktop.
Django-plpy triggers without using ORM in them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_plpy.installer import pltrigger | |
@pltrigger(event="INSERT", when="BEFORE", table="books_book") | |
def pl_trigger(td, plpy): | |
# mind triggers don't return anything | |
td["new"]["name"] = td["new"]["name"] + "test" | |
td["new"]["amount_sold"] = plpy.execute("SELECT count(*) FROM books_book")[0][ | |
"count" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment