Model Signals
See original GitHub issueDoes tortoise saves the old values before a save? So I can compare what has been changed.
The context here is I’m trying to create a “application trigger” module, for example :
#When a task is done, all its child tasks should be automatically done too
@Task.bind('after-save')
async def update_child_tasks(self, old_values):
if old_values.status != self.status:
if self.status == 'done'
await Task.filter(mother_task=self).update(status='done')
This is only a small example, there are many other cases where I need triggers like this
Hope it is understood what I’m trying to do, emphasis on trying, I’m accepting ideas on different ways to approach this.
Also it wouldn’t work on batch QuerySet methods, like update or batch_create, if anyone has any idea on how to overcome this that’d be great
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
Signals - Django documentation
The django.db.models.signals module defines a set of signals sent by the model system. ... Signals can make your code harder to maintain. Consider...
Read more >Signal Model - an overview | ScienceDirect Topics
The signal models used in vibration analysis include random process models and time series models that approximate discrete time processes encountered in ...
Read more >Amazon.com: Hobby Train Signals, Signs & Lights
Online shopping for Train Signals, Signs & Lights from a great selection at Toys ... JTD03 5pcs Model Railway 2-Light Block Signal Green/Red...
Read more >Signals, Signs, Billboards - Signals - Page 1 - ModelTrainStuff
Add realistic details to your train layout with signals for railroad track. ... Showcase Miniatures N 518 Model 3 Magnetic Flagman Wigwag Signal...
Read more >How to Create and Use Signals in Django ? - GeeksforGeeks
Signals are used to perform any action on modification of a model instance. The signals are utilities that help us to connect events...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my code, I use before saves to enforce business rules, but for that I had to change the code so that I can see what has been changed.
I mean, if there are uses for it in SQL there will be here too.
But, at least in my case, without the ability to check before/after (which fields have changed) it wouldn’t be too useful.
@mojimi Unfortunately not. SQLite reports the no of lines filtered, has no syntax to return other data during an update. MySQL reports the no of lines updated, has no syntax to return other data during an update. Postgres eports the no of lines filtered(not updated), and has syntax to return data.
In none of the cases we get the right data (or any data).
The best would be to run two queries in a transaction:
.filter()
and by NOT parameters to.update()
→ This should get you the object that is going to change in the next queryAnd depending on the database and the configured isolation level, would possibly raise an exception if any race gets detected. So the data would be pretty close to trustworthy, but not guaranteed 100% trustworthy.
Django’s signals is more-or-less what I was talking about 👍