Adding custom fields to auth_user table in Django

后端 未结 2 2138
孤独总比滥情好
孤独总比滥情好 2021-02-14 08:41

Currently I created another class/table called MyAppUser with my custom columns (such as address and phone number) that has a foreign key to Django\'s authenticatio

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 08:50

    That is generally the method I prefer, I don't like to touch the Django user just to be safe. This way you know you aren't going to conflict with anything in the user model, and it makes it clear which code is framework code and which is your code.

    I normally don't call it MyAppUser but more usually, something like UserSettings. I don't want my user related classes to be confused as replacements for the User object, but simply provide more information.

    Generally in apps you will have foreign keys to User all over the place, so I still use Django User class for all those as well. I find it keep things cleaner.

    I have tried to subclass User and found it didn't give me much, and ended up confusing things, more than they needed to be.

提交回复
热议问题