Extending django user model and errors

django 1.8.2

this is my model:

class AppUser(AbstractUser):
    _SEX = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    _pregex  = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
    phone    = models.CharField(validators=[_pregex], max_length=16, blank=True)
    gender   = models.CharField(max_length=1, blank=True, choices=_SEX)
    birthday = models.DateField(blank=True)
    vericode = models.CharField(max_length=40, blank=True) # verification code over SMS?
    verified = models.DateTimeField(null=True) # datetime stored when verification happened

    @property
    def age(self):
        today = date.today()
        return today.year - self.birthday.year - ((today.month, today.day) < (self.birthday.month, self.birthday.day))

      

these are my settings:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# register externals
EXTERNAL_LIBS_PATH = os.path.join(BASE_DIR, "_externals", "libs")
EXTERNAL_APPS_PATH = os.path.join(BASE_DIR, "_externals", "apps")
APPS_PATH = os.path.join(BASE_DIR, "apps")
sys.path = ["", EXTERNAL_APPS_PATH, EXTERNAL_LIBS_PATH, APPS_PATH] + sys.path

# TEST PATH
TEST_ASSETS = os.path.join(BASE_DIR, "_test")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition
INSTALLED_APPS = (
    'suit',
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.postgres',
    'cacheops',
    'rest_framework',
    'rest_framework.authtoken',
    'corsheaders',
    'djoser',
    'consents'
)

# Custom model for Auth
# AUTH_USER_MODEL = 'consents.AppUser'

      

my folder structure is this

app
  -settings.py etc
apps
  -consents

      

Added path to applications in settings.py: APPS_PATH = os.path.join (BASE_DIR, "apps") in sys.path,

when i run python manage.py syncdb (or whatever) i get this:

(cmr) F:\_Projects\cmr\containers\backend>python manage.py syncdb
F:\_Projects\cmr\.venv\cmr\lib\importlib\_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
  return f(*args, **kwds)

SystemCheckError: System check identified some issues:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'AppUser.groups'.
        HINT: Add or change a related_name argument to the definition for 'User.groups' or 'AppUser.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'AppUser.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'AppUser.user_permissions'.
consents.AppUser.groups: (fields.E304) Reverse accessor for 'AppUser.groups' clashes with reverse accessor for 'User.groups'.
        HINT: Add or change a related_name argument to the definition for 'AppUser.groups' or 'User.groups'.
consents.AppUser.user_permissions: (fields.E304) Reverse accessor for 'AppUser.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'AppUser.user_permissions' or 'User.user_permissions'.

      

If I uncomment this line in settings

# AUTH_USER_MODEL = 'consents.AppUser'

      

I am getting another error:

ValueError: Dependency on unknown app: consents

      

I just need to add some fields to the default User model (don't want the new one to create a completely new subclassign authassign AbstractBaseUser)

So what am I doing wrong?

+3


source to share


1 answer


Decision

  • It was necessary to delete, re-create the db
  • Delete * .pyc files
  • Delete migration folders


then python manage.py makemigrations worked fine.

+1


source







All Articles