首页 > 其他 > 详细

Django admin 外键关联默认显示用户的username

时间:2019-11-07 11:08:16      阅读:259      评论:0      收藏:0      [点我收藏+]

使用默认User表.默认显示用户username,转换成get_full_name()


/home/labsmith/venv_labsmit/lib/python3.6/site-packages/django/contrib/auth/models.py

class User(AbstractUser):
    """
    Users within the Django authentication system are represented by this
    model.

    Username and password are required. Other fields are optional.
    """

    def __str__(self):
        return self.get_full_name()

    class Meta(AbstractUser.Meta):
        swappable = 'AUTH_USER_MODEL'

添加 str 方法

暂时没发现异常,有异常在更新

Django admin 外键关联默认显示用户的username

原文:https://www.cnblogs.com/polly-ling/p/11810724.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!