I don't wont to bother you with a long text and will first show you the code. I think this should be self explanatory. If not, let me know :)
#####################
from typing import Any, Dict
from django.apps import AppConfig
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from .models import Employer
class EmployerConfig(AppConfig):
name = "employer"
verbose_name = "Employer"
def ready(self) -> None:
def post_save_user(**kwargs: Dict[str, Any]) -> None:
if kwargs['created']:
return None
user: User = kwargs['instance']
if user.employer:
return None
employer = Employer(user=user)
employer.save()
post_save.connect(post_save_user, User)
#####################
As you can see I want to create an employer and link them with the new created user.
Running the command
./manager.py createsuperuser --username username --email us...@user.com ***********
shows me that I'm wrong. There is no entry in the myapp_employer table. What did I missend?
* Django: 2.0.X
* app is installed
* python: 3.6