Reputation: 143
I want my app users to listen to the action of creating a User instance and exactly after that initialise (create) an Account instance: Unfortunately the following does not work at all:
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Account
@receiver(post_save, sender=User)
def create_account(sender, instance, created, **kwargs):
if created:
Account.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_account(sender, instance, **kwargs):
instance.account.save()
and my apps.py
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'
def ready(self):
import users.signals
I create a user but it does not dispatch the action for the receivers to created an Account instance. At leas I cannot see them in the Django default administration region.
Upvotes: 0
Views: 29