新建users的app
startapp users
自定义user类,在users/models.py:
from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. 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=10,choices=(("male","男"),("female","女")),default="female") 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 __unicode__(self): return self.username
image那个要安装pillow
pip install pillow
修改setting配置:
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"
重新makemigrations:
python manage.py makemigrations
python manage.py migrate
如果以前执行过,要删除表重新来,要么报错