I need to import a custom User model into a third party app, problem is this app import django's default User model, so:
from django.contrib.auth.models import User
I have a custom User, I could do this:
from myapp.models import User
but I want a generic solution.
I had tried:
1:
from django.contrib.auth import get_user_model
User = get_user_model()
output:
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
2:
from django.conf import settings
from django.db.models import get_model
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
User = get_model(app_label, model_name)
output:
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
3:
from django.conf import settings
User = settings.AUTH_USER_MODEL
output:
TypeError
isinstance() arg 2 must be a class, type, or tuple of classes and types
specifically need execute this code
if isinstance(author, User) and author.is_authenticated():
kwargs['author'] = u"%s <%s>" % (author.get_full_name() or author.username, author.email)
elif isinstance(author, six.string_types):
kwargs['author'] = author
How I could do it? Thanks