분리된 어플리케이션의 작업이 발생했음을 알려주고 처리할 수 있는 기능
This is sent at the beginning of a model’s save() method.
Like pre_save, but sent at the end of the save() method.
pre_save -> 데이터 DB에 저장 -> post_save
모델의 필드를 변경하거나 FK 또는 M2M을 추가하거나 변경할 때
Sent at the beginning of a model’s delete() method and a queryset’s delete() method.
Like pre_delete, but sent at the end of a model’s delete() method and a queryset’s delete() method.
Sent when a ManyToManyField is changed on a model instance. Strictly speaking, this is not a model signal since it is sent by the ManyToManyField, but since it complements the pre_save/post_save and pre_delete/post_delete when it comes to tracking changes to models, it is included here.
from django.db.models.signals import post_save
from app.user.models import User, Profile
from django.dispatch import receiver
import logging
logger = logging.getLogger(__name__)
@receiver(post_save, sender=User)
def create_my_signal(sender, instance, created, **kwargs):
if created:
try:
profile = Profile.objects.create(
user = instance,
username = instance.username
)
except Exception as e:
logger.error(e)
from django.apps import AppConfig
class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
# 기본적으로 여기까지 되어있음
def ready(self): # ready메소드 추가
import app.users.signals
``