Python “django admin”;键';类别';在'中找不到;规格参数表';。选项包括:帮助“文本、名称、单位、值”类型;
当我在管理界面中查看更改列表时,我可以看到Python “django admin”;键';类别';在'中找不到;规格参数表';。选项包括:帮助“文本、名称、单位、值”类型;,python,django,django-admin,Python,Django,Django Admin,当我在管理界面中查看更改列表时,我可以看到“名称”、“类别”、“值\u类型”、“帮助\u文本”字段,证明类别字段是正确的。但是当我点击一个参数进入变更表单时,我得到了上面的错误 这是我的管理员: @admin.register(SpecificationParameter) class SpecificationParameterAdmin(SortableAdminMixin, admin.ModelAdmin): """ For administering Specifica
“名称”、“类别”、“值\u类型”、“帮助\u文本”
字段,证明类别字段是正确的。但是当我点击一个参数进入变更表单时,我得到了上面的错误
这是我的管理员:
@admin.register(SpecificationParameter)
class SpecificationParameterAdmin(SortableAdminMixin, admin.ModelAdmin):
"""
For administering Specification Parameters
"""
# Fields shown in lists
list_display = ('name', 'category', 'value_type', 'help_text')
list_per_page = 20
# related field needs __ due to foreign key
search_fields = ['name', 'category__name']
# Change 'Save and add another' to 'Save as new' to easily create similar entries
save_as = True
# django 1.10 will default to staying on the page after creating a new one; redirects in 1.9 :(
# for this purpose, show the id
readonly_fields = ('id',)
# Modify the layout of the form, put the optional choices last
fieldsets = (
(None, {'fields': (('name', 'id'), 'category', 'units', 'help_text')}),
(_('Type'), {'fields': ('value_type',)}),
)
inlines = [SpecificationValueChoiceAdminInline]
def get_inline_instances(self, request, obj=None):
"""
Override to dynamically display choices if multiple choice or checkbox
"""
instances = []
for inline in self.inlines:
if inline == SpecificationValueChoiceAdminInline:
if obj and obj.value_type in (tup[0] for tup in SpecificationParameter.VALUE_TYPES[1][1]):
# for changes and not adds
instances += [inline(self.model, self.admin_site)]
else:
instances += [inline(self.model, self.admin_site)]
return instances
以及相关的模型片段:
class SpecificationParameter(models.Model):
"""
The fields required by parameters in the specification of a product.
"""
# _() Provides the name as a translation
name = models.CharField(_("specification parameter name (public)"), unique=True, max_length=50,
help_text=_("Be as specific as you can, for example: Minimum DC Voltage"))
# All parameters in a category need to be removed manually before it will allow you to delete the cetegory
category = models.ForeignKey(SpecificationCategory, verbose_name=_("parameter category"), on_delete=models.PROTECT,
help_text=_("Add a new or select an existing parameter section"))
help_text = models.CharField(_("help text"), max_length=160, help_text=_("Specify any additional information useful to the staff entering values"), blank=True)
....
可能是因为它是外国钥匙吗?
非常感谢您的任何想法
编辑:
删除字段集
会删除错误,但默认字段不包括类别
我尝试过django 1.10.7和1.9.9,没有任何区别,所以删除了上面的评论。必须是我所做的更改:-/我已确认
类别未出现在表单中。基本字段这是由SortableAdminMixin
引起的,因为类别位于此混合使用的模型元排序属性中
当我执行pip安装-U
时,我意外地覆盖了一个修改过的分支,这是由SortableAdminMixin
引起的,因为category
位于该mixin使用的model Metaordering
属性中
在执行pip安装-U
时,我意外地覆盖了一个修改过的分支。请显示完整的回溯和SpecificationParameter
模型。请注意,更改self.inlines
不是线程安全的。最好是重写。我可以看到一个异常,那就是帮助文本,你有一个同名的字段吗?否则你的模型就有问题了,django怎么会把name字段中定义的help_文本当作另一个字段呢?@Alasdair谢谢你的提示,我将研究get_inline_实例。添加了一个模型片段。我应该如何共享回溯?在黄色的Django错误页面上(当DEBUG=True
时),有一个复制和粘贴视图的开关,可以轻松获取回溯并将其添加到您的问题中。请显示完整的回溯,以及SpecificationParameter
模型。请注意,更改self.inlines
不是线程安全的。最好是重写。我可以看到一个异常,那就是帮助文本,你有一个同名的字段吗?否则你的模型就有问题了,django怎么会把name字段中定义的help_文本当作另一个字段呢?@Alasdair谢谢你的提示,我将研究get_inline_实例。添加了一个模型片段。我应该如何共享回溯?在黄色的Django错误页面上(当DEBUG=True
时),有一个复制和粘贴视图的开关,可以轻松获取回溯并将其添加到问题中。