Django Oscar中的新增添加字段未显示在“个人资料编辑”表单中? [英] Newly added fields not showing in Profile Edit form in Django Oscar?
问题描述
我想扩展用户模型。我遵循此文档中提到的步骤。我创建了一个新的应用程序 extended_user
其models.py读作:
I want to extend the User model. I followed the steps mentioned in this doc. I made a new app extended_user
whose models.py reads as :
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我提到
In settings.py I mention
AUTH_USER_MODEL = "extended_user.User"
我制作并运行迁移。在个人资料视图中,我可以看到昵称
字段,但在配置文件编辑视图中,我不知道。我需要做什么才能看到Profile Edit窗体中新添加的字段?
I make and run migrations. In profile view I can see nickname
field but in Profile Edit view I don't. What do I have to do to see the newly added field in the Profile Edit form ?
推荐答案
我假设你不使用一个单独的rofile类。在这种情况下,Oscar 设置 ProfileForm
指向 UserForm
课程。
I assume that you do not use a separate rofile class. In that case Oscar sets ProfileForm
to point to the UserForm
class.
该类依次有一个或多或少的硬编码列表字段
。 (实际上它说这个列表中存在哪个字段)。
That class in turn has a more-or-less hardcoded list of fields
. (In reality it says "whichever fields exist out of this list".)
从这里开始,最简单的方法是覆盖 customer.forms.ProfileForm
使用您自己的类,使用您新定义的用户
模型和更适合您的用户名的字段列表。 (创建一个 your_app.customer.forms
模块,并在其中定义一个 ProfileForm
。)
The easiest way to go forward from here is to override customer.forms.ProfileForm
with your own class that uses your newly defined User
model and the list of fields that better suits your usecase. (Create a your_app.customer.forms
module and define a ProfileForm
inside.)
这篇关于Django Oscar中的新增添加字段未显示在“个人资料编辑”表单中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!