简体   繁体   English

我如何在抽象用户上添加其他字段

[英]How do i add other fields on Abstract User

This is my model.这是我的模型。 When i make migrations it is not showing up on my admin page.当我进行迁移时,它没有显示在我的管理页面上。

 class User(AbstractUser): # TODO User will be associated with one or more chama accounts id_number = models.IntegerField(default=0) phone_number = models.IntegerField(default=0) active_chama = models.ManyToManyField("Chama")

You will have to set the AUTH_USER_MODEL setting in your settings.py if you use the AbstractUser model to create a custom one.如果您使用 AbstractUser 模型创建自定义模型,则必须在settings.py AUTH_USER_MODEL设置。

AUTH_USER_MODEL = "myApp.User"

Here is the relevant part in the docs这是文档中的相关部分

Edit:编辑:

Like stated in the comments you will have to register your custom model in your custom user apps admin.py就像评论中所述,您必须在您的自定义用户应用程序admin.py注册您的自定义模型

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User

admin.site.register(User, UserAdmin)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM