Below is my code in the signal.py file located in the package where the auth model is defined.
@receiver(post_migrate, sender=settings.AUTH_USER_MODEL) def define_groups(sender, **kwargs): # Create groups Group.objects.get_or_create(name='Promoter') Group.objects.get_or_create(name='Client') Group.objects.get_or_create(name='Superuser') Group.objects.get_or_create(name='Staff')
The documentation ( https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#referencing-the-user-model ) states that it should be installed as
sender=settings.AUTH_USER_MODEL
so far this only works for post_save, as indicated in the sample documentation.
I have already tried get_user_model () as well as directly using my_custom_user.models .
get_user_model () returns an error, while setting models as sender works fine, as -
from . import models @receiver(post_syncdb, sender=models) def define_groups(sender, **kwargs): # Create groups Group.objects.get_or_create(name='Promoter') Group.objects.get_or_create(name='Client') Group.objects.get_or_create(name='Superuser') Group.objects.get_or_create(name='Staff')
But according to the documentation, this is the wrong way to reference a user model and just an ugly workaround.
It would help me to help me with the solution, so I can add these groups with the first migration of the user model.
thanks
EDIT: using get_user_model () returns the following error -
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.