1

我一直在关注这个网站。我想添加一个额外的字段电子邮件以及模型中可用的电子邮件。我有

表格.py

从 django 导入表单 从 django.forms 导入 ModelForm 导入 django.forms

从 new_db.models 导入作者、出版商、书籍

class ContactForm(forms.ModelForm):
    email = forms.EmailField(required=True,)

    class meta:
        model=Publisher
        fields=['first_name','last_name']

    def __init__(self, *args, **kwargs):
     if kwargs.get('instance'):
        email = kwargs['instance'].email
        kwargs.setdefault('initial', {})['email'] = email
     return super(ContactForm, self).__init__(*args, **kwargs)  

视图.py

 class CreateContact(CreateView):
        model=Publisher
        template_name='CreatePublisher.html'
        form_class=ContactForm

我遇到的错误是

Exception Value:    ModelForm has no model class specified.
    Exception Location: C:\Python27\lib\site-packages\django\forms\models.py in __init__, line 238
4

1 回答 1

12

你有一个错字

class meta:

应该

class Meta:

注意情况。

更多在这里https://docs.djangoproject.com/en/dev/topics/db/models/#meta-inheritance

于 2013-11-10T03:37:46.293 回答