1、自定义用户表
from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. class UserProfile(AbstractUser): ##引用Django内置的AbstractUser表,并添加下列字段 nick_name = models.CharField(max_length=50,default="",verbose_name=u"昵称") birday = models.DateField(verbose_name=u"生日",null=True,blank=True) gender = models.CharField(max_length=10,choices=(("male",u"男"),("female",u"女")),default="female") address = models.CharField(max_length=100,default=u"",verbose_name=‘地址‘) mobile = models.CharField(max_length=11,null=True,blank=True,verbose_name=‘手机号码‘) image = models.ImageField(upload_to="image/%Y/%m",default=u"image/default.png",max_length=100) class Meta: verbose_name = u"用户信息" verbose_name_plural = verbose_name def __unicode__(self): return self.username
2、在settings注册APP,并配置用户表model参数AUTH_USER_MODEL
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘users‘ ] AUTH_USER_MODEL = "users.UserProfile"
时间: 2024-10-10 01:55:25