Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Signals
- 1. Create file signals.py
- from django.contrib.auth import get_user_model
- from django.db.models.signals import post_save
- from django.dispatch import receiver
- from petstagram.accounts.models import Profile
- UserModel = get_user_model()
- @receiver(post_save, sender=UserModel)
- def user_created(sender, instance, created, **kwargs):
- if not created:
- return
- Profile.objects.create(user=instance)
- 2. In apps.py we have to write
- from django.apps import AppConfig
- class AccountsConfig(AppConfig):
- default_auto_field = "django.db.models.BigAutoField"
- name = "my_project_name.accounts"
- def ready(self):
- import my_project_name.accounts.accounts.signals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement