社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

django1.6 自定义扩展user模块报错which has not been installed or is abstract

blackholll • 11 年前 • 9776 次点击  

按照官方文档说明自定义了user模块。 文件目录结构如下:

accounttest
--account
----__init__.py
----admin.py
----models.py
----tests.py
----views.py
--accounttest
----__init__.py
----settings.py
----urls.py
----wsgi.py
--manage.py

代码如下:

**models.py**


# coding=utf-8
from django.db import models

# Create your models here.

import uuid
from django.conf import settings
from django.contrib.auth.models import BaseUserManager,AbstractBaseUser

class PassportManager(BaseUserManager):
    def create_user(self,email,username,password=None):
        if not email:
            raise ValueError('Users must have a email address')
        user = self.model(
              email = PassportManager.normalize_email(email),
              username = username,
              uuid = str(uuid.uuid1()),
        )
        user.set_password(password)
        user.uuid = str(uuid.uuid1())
        user.save(using=self._db)

    def create_superuser(self,email,username,password):
        user = self.create_user(email,
                              username =username,
                              password = password,)
        user.uuid = str(uuid.uuid1())
        user.is_staff = True
        user.is_active = True
        user.is_admin = True
        user.sace(using=self._db)
        return user
class Passport(AbstractBaseUser):
    uuid = models.CharField(max_length=36,unique=True, db_index=True)
    username = models.CharField(max_length=40, unique=True, db_index=True)
    email = models.EmailField(max_length=254)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    is_admin = models.BooleanField(default=False)
    address = models.CharField(max_length=140,blank=True, null=True)
    dep = models.CharField(max_length=30,blank=True, null=True)
    role = models.CharField(max_length=30,blank=True, null=True)
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']
    objects = PassportManager()

    class Meta:
        app_label = 'passport'

=====================

**settings.py**:


"""
Django settings for accounttest project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/


    


For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm8n%teued!sq%)_6*%(vhz%7s&i6!0hdkwk#ecryi9u%y4r%v+'

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

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

AUTH_USER_MODEL='account.Passport'

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounttest',
    'account'
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'accounttest.urls'

WSGI_APPLICATION = 'accounttest.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'accounttest3',                      # Or path to database file if using sqlite3.
        'USER': 'accounttest3',                      # Not used with sqlite3.
        'PASSWORD': '123456',                  # Not used with sqlite3.
        'HOST': '192.168.138.58',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

在执行python manage.py validate的时候报错了:

“”“
CommandError: One or more models did not validate:
admin.logentry: 'user' has a relation with model account.Passport, which has either not been installed or is abstract.
auth.user: Model has been swapped out for 'account.Passport' which has not been installed or is abstract.

”“”

请问如何解决啊

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/384
 
9776 次点击  
文章 [ 5 ]  |  最新文章 11 年前
Py站长
Reply   •   1 楼
Py站长    11 年前

@blackholll 嗯,不错

blackholll
Reply   •   2 楼
blackholll    11 年前

@Django中国社区 对比了下官网的例子,去掉了

class Meta:
        app_label = 'passport'

就好了,不太理解啊。 app_label应该只是这个class 在admin界面上的显示名啊

Py站长
Reply   •   3 楼
Py站长    11 年前

http://stackoverflow.com/questions/16230293/admin-logentry-user-has-a-relation-with-model-class-api-models-user-whic

Py站长
Reply   •   4 楼
Py站长    11 年前

你的INSTALLED_APPS 中的APp是account

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounttest',
    'account'
)

但是你的app_label 是passport

class Meta:
    app_label = 'passport'

你看下是不是这个原因

blackholll
Reply   •   5 楼
blackholll    11 年前

晕 ,发出来竟然全乱了