I\'m using a custom user model, extended with AbstractUser. Here\'s my models.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from d
I had the same error when I tried to get the auth user by writing:
User = get_user_model()
at the top of my models.py:
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth import get_user_model
User = get_user_model()
class User(AbstractUser):
is_official = models.BooleanField('official status', default=False)
is_distro = models.BooleanField('distro status', default=False)
is_subscriber = models.BooleanField('subscriber status', default=False)
I was able to resolve it by moving the User = get_user_model() below the User model definition, which makes sense as the get_user_model() getting called at the top of the User model definition meant it was referencing a model that doesn't exist yet. Here is the code layout that worked:
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth import get_user_model
class User(AbstractUser):
is_official = models.BooleanField('official status', default=False)
is_distro = models.BooleanField('distro status', default=False)
is_subscriber = models.BooleanField('subscriber status', default=False)
def __str__(self):
return self.username
User = get_user_model()
You may not have this exact layout but I guess the main point is To Not Reference A Model Before Its Definition In The Same File, This Is Why Import Statements Come At The Top.