When to use the Custom User Model in Django 1.5

前端 未结 1 610
醉酒成梦
醉酒成梦 2021-01-31 21:10

I have a question regarding the custom user model in Django 1.5

So right now the default user model looks just fine to me, I just need to add a few other variables such

相关标签:
1条回答
  • 2021-01-31 22:07

    You want to extend your user model to the AbstractUser and add your additional fields. AbstractUser inherits all of the standard user profile fields, whereas AbstractBaseUser starts you from scratch without any of those fields.

    It's hard to define best practices this close to the release, but it seems that unless you need to drastically redefine the User model, then you should use AbstractUser where possible.

    Here are the docs for extending the User model using AbstractUser

    Your models.py would then look something like this:

    class MyUser(AbstractUser):
        gender = models.DateField()
        location = models.CharField()
        birthday = models.CharField()
    

    MyUser will then have the standard email, password, username, etc fields that come with the User model, and your three additional fields above.

    Then you need to add the AUTH_USER_MODEL to your settings.py:

    AUTH_USER_MODEL = 'myapp.MyUser'

    0 讨论(0)
提交回复
热议问题