1👍
Yes as said in the above comment you can make use of signals.
Give this a try,
Create a signals.py
file in your app directory.
# signals.py
from django.db.models.signals import post_save, post_delete, pre_delete
from django.dispatch import receiver
from .models import AppConfig
@receiver(post_save, sender=AppConfig)
def log_appconfig_update(sender, instance, created, **kwargs):
if created:
action = "created"
else:
action = "modified"
print(f"AppConfig {action}: {instance}")
# Write Your Logic Here
@receiver([post_delete, pre_delete], sender=AppConfig)
def log_appconfig_delete(sender, instance, **kwargs):
print(f"AppConfig deleted: {instance}")
then register the signals in your apps.py
from django.apps import AppConfig # don't confuse with models.AppConfig
class YourAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'your_app_name'
def ready(self):
import your_app_name.signals
With this setup, every time an AppConfig instance is created, modified, or deleted, the corresponding message will be printed to terminal.
Source:stackexchange.com