AbstractUser Django full example

前端 未结 2 1021
盖世英雄少女心
盖世英雄少女心 2021-02-02 00:48

I am new to Django and I have been trying this for weeks, but could not find a way to solve this problem.

I want to store additional information like user mobile number,

2条回答
  •  时光说笑
    2021-02-02 01:46

    You have confused yourself a bit here. The idea of subclassing AbstractUser - and defining AUTH_USER_MODEL as your subclass - is that the new model completely replaces auth.models.User. You shouldn't be importing the original User at all, and you certainly should be calling User.objects.create_user(): your new model's manager now has its own create_user method.

    Because of this, there's no reason to muck about with inline admins. Your UserProfile should be registered in the admin using the existing django.contrib.auth.admin.UserAdmin class.

提交回复
热议问题