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

使用默认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 方法

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

posted @ 2019-11-07 10:58  MAU  阅读(1459)  评论(0编辑  收藏  举报