我想制作外键并使用settings.AUTH_USER_MODEL但我收到的错误是这样的:
ERRORS:
kerajinan.Product.author: (fields.E300) Field defines a relation with model 'settings.AUTH_USER_MODEL', which is either not installed, or is abstract.
这是setting.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'kerajinan',
'bootstrap3',
'registration',
)
AUTH_USER_MODEL = 'kerajinan.UserProfile'
和这个model.py:
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.utils.text import slugify
from django.db.models import ImageField
from django.core.validators import RegexValidator
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser, PermissionsMixin
class Product(models.Model):
author = models.ForeignKey('settings.AUTH_USER_MODEL')
userprofile = models.ForeignKey('UserProfile')
title = models.CharField(max_length=50)
def __str__(self):
return self.title;
你能帮忙解决这个问题吗?
答案 0 :(得分:2)
您已使用文字字符串" settings.AUTH_USER_MODEL"在你的ForeignKey中。您应该使用实际设置值。
author = models.ForeignKey(settings.AUTH_USER_MODEL)