3

我正在使用 django-allauth,我希望能够将新字段添加到我的用户模型中。对你来说最好的方法是什么?

4

2 回答 2

3

我使用用户名。但我相信它看起来几乎一样;)

class UserProfile(UserenaBaseProfile):

        user = models.OneToOneField(User, unique=True)
        city = models.CharField(max_length=32, blank=True, null=True)

在 settings.py 中:

AUTH_PROFILE_MODULE = 'accounts.UserProfile'
于 2012-07-19T05:55:57.477 回答
3

请参阅文档存储有关用户的其他信息,制作与OneToOneField相关的模型User

from django.contrib.auth.models import User

class UserProfile(models.Model):
    # This field is required.
    user = models.OneToOneField(User)

    # Other fields here
    accepted_eula = models.BooleanField()
    favorite_animal = models.CharField(max_length=20, default="Dragons.")
于 2012-07-19T05:56:14.800 回答