Django: xyz.fieldsets[0][1]['fields'] 指的是字段“123”;表格中缺少的内容
我毫不怀疑这将是一个非常愚蠢的问题。但实在是想不通,所以还是想问一下。
在 /svsite/src/svsite/member/models/svuser.py (一个有点不寻常的位置,请参阅这个问题 将 Django 管理表单放在不同的文件中)。
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin, UserChangeForm as DjangoUserChangeForm
from svsite.member.models.svuser import svUser
class UserChangeForm(DjangoUserChangeForm):
class Meta:
pass
class svUserAdmin(UserAdmin):
form = UserChangeForm
readonly_fields = ('date_joined', 'last_login', 'last_update', )
fieldsets = \
(
(
'Login',
{
'classes': ('collapse', ),
'fields':
(
'username',
'password',
'is_active',
'email_verified',
'awaiting_user_confirmation',
),
}
),
(
'Personal info',
{
'fields':
(
'first_name',
'middle_name',
'last_name',
),
}
),
)
[...]
在 /svsite/src/svsite/member/admin/svuser.py 的模型中:
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User, UserManager
class svUser(User):
email_verified = models.BooleanField(default = False)
awaiting_user_confirmation = models.BooleanField(
_('approved by board'), default = False, help_text=_('This user\'s identity was confirmed by the board or another authority.'))
[...]
我得到的错误:
'svUserAdmin.fieldsets[0][1]['fields']' refers to field 'password' that is missing from the form.
如果我注释密码,错误将移至下一个字段。如果它是默认用户模型字段或我在从 user 继承的 svUser 中添加的字段,则为独立字段。非常令人惊讶(对我来说),用户名似乎是唯一有效的字段,没有任何问题。
我发现这个问题 Django ModelAdmin - fieldsets ... field 'date ' 表单中缺少,即使这些字段不是 auto_now,我也将它们添加到 readonly_fields 中,这使得错误消失了。但显然,将所有字段设置为只读并不是一种选择。
这可能是一些与代码无关的愚蠢的东西,但我真的找不到它,在我看来它确实应该有效。非常感谢任何帮助!
I have little doubt that this will be a really stupid question. But I really can't figure it out so I'll ask it anyway.
In /svsite/src/svsite/member/models/svuser.py (a little unusual location, see this question Place Django admin forms in different files).
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin, UserChangeForm as DjangoUserChangeForm
from svsite.member.models.svuser import svUser
class UserChangeForm(DjangoUserChangeForm):
class Meta:
pass
class svUserAdmin(UserAdmin):
form = UserChangeForm
readonly_fields = ('date_joined', 'last_login', 'last_update', )
fieldsets = \
(
(
'Login',
{
'classes': ('collapse', ),
'fields':
(
'username',
'password',
'is_active',
'email_verified',
'awaiting_user_confirmation',
),
}
),
(
'Personal info',
{
'fields':
(
'first_name',
'middle_name',
'last_name',
),
}
),
)
[...]
In the model I have at /svsite/src/svsite/member/admin/svuser.py:
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User, UserManager
class svUser(User):
email_verified = models.BooleanField(default = False)
awaiting_user_confirmation = models.BooleanField(
_('approved by board'), default = False, help_text=_('This user\'s identity was confirmed by the board or another authority.'))
[...]
The error I get:
'svUserAdmin.fieldsets[0][1]['fields']' refers to field 'password' that is missing from the form.
If I comment password, the error moves to the next field. Independent if it's a default user model field or one I added in the svUser inherited from user. Very surprisingly (to me), username seems to be the only field that works, no problems on that one.
I found this question Django ModelAdmin - fieldsets ... field 'date' missing from the form and even though the fields are not auto_now, I added them to readonly_fields and that made the error go away. Obviously though, making all fields read-only is not an option.
It's probably something stupid not really related to code but I really can't find it, seems to me it really should be working. Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎是因为您正在将
ModelForm
用于未编辑的模型。我尝试了类似的情况并得到了类似的错误模式。
The problem appears to be because you're using a
ModelForm
for a model that you are not editing.I tried a simliar situation and got a similar error pattern.