Skip to content

Instantly share code, notes, and snippets.

@thorin-schiffer
Created December 31, 2021 15:22
Show Gist options
  • Save thorin-schiffer/2cf54594c9e506130675a2656dba2abc to your computer and use it in GitHub Desktop.
Save thorin-schiffer/2cf54594c9e506130675a2656dba2abc to your computer and use it in GitHub Desktop.
Django-plpy triggers without using ORM in them
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