Hello World

User model

自定义 User Model(扩展 AbstractUser类)
如果你对django自带的User model刚到满意, 又希望额外的field的话, 你可以扩展AbstractUser类:

 

from django.contrib.auth.models import AbstractUser

class UserInfo(AbstractUser):
    """
    用户信息
    """
    nid = models.BigAutoField(primary_key=True)
    nickname = models.CharField(verbose_name='昵称', max_length=32)

 

 

可是,创建表时,出现 如下错误

ERRORS:
app01.UserInfo.groups: (fields.E304) Reverse accessor for 'UserInfo.groups' clashes with reverse accessor for
'User.groups'.
        HINT: Add or change a related_name argument to the definition for 'UserInfo.groups' or 'User.groups'.
app01.UserInfo.user_permissions: (fields.E304) Reverse accessor for 'UserInfo.user_permissions' clashes with r
everse accessor for 'User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'UserInfo.user_permissions' or 'User
.user_permissions'.
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'UserInfo
.groups'.
        HINT: Add or change a related_name argument to the definition for 'User.groups' or 'UserInfo.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse ac
cessor for 'UserInfo.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'UserInfo
.user_permissions'.
o.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with
 reverse accessor for 'UserInfo.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'User.user_permissions' o 
r 'UserInfo.user_permissions'.

 

解决方案:

在settings.py中设置:
  格式:   AUTH_USER_MODEL = "<appname>.表名" AUTH_USER_MODEL = "app01.UserInfo"(自己的)

 

posted @ 2017-09-09 12:12  nayike  阅读(269)  评论(0编辑  收藏  举报

Hello