Django 更改继承的表单元类

标签 django django-forms

我要编辑Meta ClassModelForm 继承其数据的表单.我只想添加一个字段,我不想重复所有表单。

# NuevaBibliotecaCompartida is a ModelForm

class EditarBibliotecaCompartida(NuevaBibliotecaCompartida):

    class Meta:
        fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')

我收到错误 ModelForm has no model class specified ,当然,因为我在添加字段时覆盖了 Meta 类。我该如何解决这个问题?

最佳答案

您需要显式地继承父级的 Meta类(class):

class Meta(NuevaBibliotecaCompartida.Meta):
    # `model` will now be inherited
    fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')

关于Django 更改继承的表单元类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33534950/

相关文章:

django - uwsgi不创建套接字文件

javascript - javascript日期对象与python日期时间对象兼容吗

python - Django 中的断言错误

python - ImportError: 仅当在 heroku 上部署 django 应用程序时才出现 win32

html - 如何让我的 Django 表单保存图像?

python - Django 表单和 ModelChoiceField : Add HTML optgroup element to specific objects in QuerySet?

django - 使用特定值预填充 django 中的表单选择字段并初始化它

django - Django 存储系统的差异

python - 有很多选择的 Django 选择字段 - 是否有一个简单有效的解决方案?

Django FormWizard - 如何根据上一步动态创建表单集