当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Why not to extend User in Django REST

问题描述:

I am using Django REST to create users for my app.

Everywhere i look at, for users they extend AbstractBaseUser.

I tried extending the User model, and it seems to work just fine.

I have an PersonalAbstractUser that extends the Django User. Then, Worker and Client extends PersonalAbstractUser.

Login and custom permissions seem to work just fine up until now, but i am getting concerned when i see that no one else is extending User...

Why is that? Did i miss something?

网友答案:

This is not a question about Django REST, but about Django itself.

The problem with extending the User object directly is that it is already a concrete model, so extending it will use multi-table inheritance. That's not usually a good idea - especially if you're further extending it.

AbstractUser is an abstract model, but (unlike AbatractBaseUser) contains all the fields that User defines. You should use that.

分享给朋友:
您可能感兴趣的文章:
随机阅读: