修改django默认的user表

1. 创建users的app,并在model.py中写

注:一定要将email设置成外键,因为一个邮箱只能对应一个帐号,这样才能进行密码找回

class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50,verbose_name=u'昵称',default=u"")
    birday = models.DateField(verbose_name=u"生日",null=True,blank=True)
    gender = models.CharField(max_length=6,choices=(('male',u'男'),('female',u'女')),default='female')
    address = models.CharField(max_length=100,default=u"")
    mobile = models.CharField(max_length=11,verbose_name=u"手机",null=True,blank=True)
    image = models.ImageField(upload_to="image/%Y/%m",default="image/2018/05/default_middile_2.png",max_length=100)

    def __str(self):
        return self.username

    class Meta:
        verbose_name = u"用户信息"
        verbose_name_plural = verbose_name
        unique_together = (("email"),)

2. 然后在settings中注册app

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"

3. 运行 python manage.py migrate  输入 yes 

(testvir2) E:\myGitHup\python\DjangoDdu>python manage.py migrate
Operations to perform:
  Apply all migrations: sessions, auth, users, admin, contenttypes, t1
Running migrations:
  Rendering model states... DONE
  Applying users.0001_initial... OK
The following content types are stale and need to be deleted:


    auth | user

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.


    Type 'yes' to continue, or 'no' to cancel: yes

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值