1 导入AbstractUser
from django.contrib.auth.models import AbstractUser
1
2 创建类UserProfile并继承AbstractUser
class UserProfile(AbstractUser):
1
3 创建自己需要的UserProfile字段
class UserProfile(AbstractUser):
nick_name = models.CharField(max_length=50, verbose_name=u'昵称', default='')
birthday = models.DateField(verbose_name=u'生日', null=True, blank=True)
gender = models.CharField(choices=(('male', u'男'), ('female', u'女')), default='male', verbose_name=u'性别')
address = models.CharField(max_length=100, verbose_name=u'地址')
1
2
3
4
5
4 在setting中重载AUTH_USER_MODEL 方法
AUTH_USER_MODEL = 'users.UserProfile'
1
5 注意:如果在migrate时报错
- django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.
1
把数据库中的表删除重新migrate即可
文章引用自 davidghj 侵删.