Django Change继承表单元类 [英] Django Change inherited form meta class
本文介绍了Django Change继承表单元类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编辑一个从 ModelForm
继承其数据的表单的元类
。我只想添加一个字段,我不想重复所有表格。
I want to edit the Meta Class
of a form that inherits its data from a ModelForm
. All I want is to add one field, I don't want to repeat all the form.
# NuevaBibliotecaCompartida is a ModelForm
class EditarBibliotecaCompartida(NuevaBibliotecaCompartida):
class Meta:
fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')
我收到错误 ModelForm没有指定模型类
,当然,因为添加字段时我将覆盖Meta类。我该如何解决呢?
I get the error ModelForm has no model class specified
, of course, because I am overriding the Meta class when I add a field. How can I solve this?
推荐答案
您需要明确地将父级的元子类化。 c> class:
You need to explicitly subclass the parent's Meta
class:
class Meta(NuevaBibliotecaCompartida.Meta):
# `model` will now be inherited
fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')
这篇关于Django Change继承表单元类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文