Django Custom auth_user

1 Import AbstractUser

Import AbstractUser django.contrib.auth.models from
1
2 to create a class UserProfile and inherit AbstractUser

UserProfile class (AbstractUser):
1
3 fields they need to create 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 Note: If the error migrate during

  • django.db.migrations.exceptions.InconsistentMigrationHistory: Applied Migration admin.0001_initial the before the ITS IS ON dependency users.0001_initial Database 'default'.
    1
    of the database tables can be deleted to re-migrate
    ----------- ----------
    article quoted from davidghj invasion deleted.

Guess you like

Origin www.cnblogs.com/luowenConnor/p/11259187.html