我正在尝试自定义djoser的createuser端点。为此,我已按照此链接https://github.com/jcugat/django-custom-user安装了django自定义用户。这是我的models.py
from django.db import models
from custom_user.models import AbstractBaseUser
class Profile(AbstractBaseUser):
account_address = models.CharField(max_length=30, blank=True)
和serializers.py
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
class UserRegistrationSerializer(BaseUserRegistrationSerializer):
class Meta(BaseUserRegistrationSerializer.Meta):
fields = ('url', 'id', 'email', 'first_name', 'account_address', 'password')
在app.admin.py中我已按以下方式注册。
from django.contrib import admin
from custom_user.admin import UserAdmin
from .models import Profile
class MyCustomEmailUserAdmin(UserAdmin):
"""
You can customize the interface of your model here.
"""
pass
# Register your models here.
admin.site.register(Profile, UserAdmin)
任何线索在这里有什么问题?
答案 0 :(得分:1)
从外观上看,您似乎在设置中有以下内容:
AUTH_USER_MODEL = "your_app.Profile"
对于您的个人资料模型,您继承自AbstractBaseUser
的{{1}}。
我相信你的意思是继承自AbstractEmailUser。因此,您的"简介"模型实际上需要:
from django.contrib.auth.models import AbstractBaseUser