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 方法

暫時沒發現異常,有異常在更新


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM