官术网_书友最值得收藏!

Solution details

The officially recommended solution is to create a user profile model. It should have a one-to-one relation with your user model. All the additional user information is stored in this model:

class Profile(models.Model): 
    user = models.OneToOneField(settings.AUTH_USER_MODEL, 
                                on_delete=models.CASCADE,
primary_key=True)

It is recommended that you set the primary_key explicitly to True to prevent concurrency issues in some database backends such as PostgreSQL. The rest of the model can contain any other user details, such as birth-date, favorite color, and so on.

While designing the profile model, it is recommended that all the profile detail fields must be nullable or contain default values. Intuitively, we can understand that a user cannot fill out all their profile details while signing up. Additionally, we will ensure that the signal handler also doesn't pass any initial parameters while creating the profile instance.

主站蜘蛛池模板: 彭州市| 临澧县| 富蕴县| 哈巴河县| 德昌县| 全椒县| 宁国市| 来凤县| 太白县| 景宁| 辽阳县| 瑞昌市| 乌兰县| 安顺市| 仁寿县| 富源县| 洪泽县| 台东县| 哈尔滨市| 都江堰市| 安福县| 辛集市| 永嘉县| 瑞安市| 东光县| 灌南县| 陇南市| 阿坝| 边坝县| 玛沁县| 阜南县| 从化市| 高陵县| 麻城市| 漾濞| 保定市| 武威市| 定襄县| 临朐县| 天峻县| 灵川县|