文件结构
fishBooked.setting.py
os.sys.path.insert(0,os.path.join(BASE_DIR,'users'))
AUTH_USER_MODEL="users.UserProfile"
users.models.py
from django.db import models
# Create your models here.
#覆盖Auth.user表的UserProfile表
from django.contrib.auth.models import AbstractUser
class UserProfile(AbstractUser):
nick_name = models.CharField(max_length=50, verbose_name='呢称', default="")
birday = models.DateField(verbose_name='生日', null=True, blank=True)
gender = models.CharField(max_length=5, choices=(('male', "男"), ('female', '女')), default="")
address = models.CharField(max_length=100, default="")
mobile = models.CharField(max_length=11, null=True, blank=True)
image = models.ImageField(upload_to="image/%Y/%m", default="image/default.png", max_length=100)
class Meta:
verbose_name = "用户信息"
verbose_name_plural = verbose_name
def __str__(self):
return str(self.username)
xadmin
xadmin虽然功能更加丰富,但是体积更大,运行得很慢,一般自己用admin就够了,不愿意花时间去配置。
把extra_apps定义为根目录,用xadmin的时候就可以直接import
import xadmin
fishBooked.setting.py
os.sys.path.insert(0,os.path.join(BASE_DIR,'extra_apps'))
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'fish',
'xadmin',
'crispy_forms',
'reversion',
]
热门评论
这样UserProfile不调用xadmin.site.register就自动注册到admin中去了,如何自定义注册呢?