且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django的。如何在用户模型中添加额外字段并将其显示在管理界面中

更新时间:2023-10-27 18:02:58

***的方法是使用用户OneToOneField创建新模型。例如

The best way is to create new Model with User OneToOneField. e.g

class UserProfile(models.Model):
   user = models.OneToOneField(User)
   phone = models.CharField(max_length=256, blank=True, null=True)
   gender = models.CharField(
        max_length=1, choices=(('m', _('Male')), ('f', _('Female'))),
        blank=True, null=True)

您可以在用户模型或UserProfile模型中与django admin一起玩,并可以在Admin中相应地显示字段

You can play with django admin either in User Model or UserProfile Model and can display the fields in Admin accordingly