[Django]-Auto Update Django Model based on other model fields

4đź‘Ť

âś…

You can use the signals feature:

Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.

The django.db.models.signals module predefines a set of signals sent by the model system. You could use the post_save signal which is triggered at the end of a model’s save() method.

from django.db.models.signals import pre_save
from django.dispatch import receiver
from myapp.models import MyModel


@receiver(post_save, sender=ValidateResult)
def my_handler(sender, **kwargs):
    ...
👤Wtower

Leave a comment