DJango signal like funcionality

So I am looking to achieve something like this:

Table1 [ID Name]
Table2 [ID Name]
Table3 [ID Name]

CategoriesTable [Category ID Name]

CategoriesTable contains a row for every entry in Table1, Table2 and Table3. The category + ID fields are used to identify which table + row is being referenced (but are not foreign keys). e.g

Category        ID    Name
Subjects        1      Maths
Subjects        2      English
Food            1      Bananas
Materials       1      Steel

What I need to do is update or insert an entry into the CategoriesTable anytime a Row is inserted or updated in Table1, Table2 or Table3. This would be done in DJango with a post_save signal which could then create/update the associated CategoriesTable row.

I am looking for something similar, but ideally all changes would sit inside 1 transaction. So I imagine some way of building an Ecto.Multi from some registered list of callbacks would be involved.

Either Ecto.Changeset.prepare_changes/2 or you can use database triggers or you can create (materialised?) view if that data can be derived from the content of tables.

3 Likes