开发者

Why shouldn’t I add additional profile fields directly to my django.contrib.auth.models.User table?

To add additional user profile information in Django, it seems that using AUTH_PROFILE_MODEL is the suggested way to go.

However, are there any disadvantages of adding additional profile fields directly to the django.contrib.auth.models.User table? To me, this seems to be much easier/straightforward (though granted, I don't yet have a grasp on using 开发者_如何学Gosignals).

Are there any very strong practical reasons against doing it this way?


I can think of following reasons:

Django updates

You have to update your contrib.auth each time you update Django so you don't break your application, and this is a maintenance nightmare. Using AUTH_PROFILE_MODEL method makes Django updates painless while it provides ability to add new information to User. This is called loose coupling i belive.

User dependant applications

3rd party application that heavily rely on User having the exact same fields will fail if you for example add fields to User model that are declared as NOT NULL or remove some that are expected to be there.

Further reading about AUTH_PROFILE_MODEL:

  • James Bennett's tips on extending User model
  • Django official docs
  • deprecation of AUTH_PROFILE_MODULE thread on django-developers mailing list


Short answer, it is more maintainable to use profiles. Based on my understanding what is advised against is making changes that will be removed once you update your Django version. If you modify django.contrib.auth.models.User model, then the changes will be removed once you update, or you will be responsibly for merging any changes done if any. On the other hand if the code lives in your application such as the profiles does then it's easier to manage. Based on that if you find another method that achieves the same, or if you don't see it as a maintenance hassle then It should not matter much one way or the other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜