gpt4 book ai didi

python - 新添加的字段未显示在 Django Oscar 的配置文件编辑表单中?

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:20 25 4
gpt4 key购买 nike

我想扩展用户模型。我按照this doc中提到的步骤进行操作。我制作了一个新的应用程序 extended_user ,其 models.py 读取为:

from django.db import models

from oscar.apps.customer.abstract_models import AbstractUser
from django.utils.translation import ugettext_lazy as _


class User(AbstractUser):

nickname = models.CharField(_("nick_name"), max_length=50, null=True, blank=True)

def get_full_name(self):
full_name = '%s %s' % (self.last_name.upper(), self.first_name)
return full_name.strip()

在settings.py中我提到

AUTH_USER_MODEL = "extended_user.User"

我进行并运行迁移。在个人资料 View 中,我可以看到nickname 字段,但在个人资料编辑 View 中却看不到。我需要做什么才能看到配置文件编辑表单中新添加的字段?

最佳答案

我假设您没有使用单独的配置文件类。在这种情况下奥斯卡sets ProfileForm 指向 UserForm类。

该类又具有或多或少硬编码的字段列表。 (实际上它说 "whichever fields exist out of this list" 。)

从这里继续前进的最简单方法是 override customer.forms.ProfileForm 与您自己的类,该类使用新定义的 User 模型和更适合您的用例的字段列表。 (创建一个 your_app.customer.forms 模块并在其中定义一个 ProfileForm。)

关于python - 新添加的字段未显示在 Django Oscar 的配置文件编辑表单中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32268262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com