Laxmi Kadariya
Laxmi Kadariya

Reputation: 1103

ModelForm has no model class specified in django

I have been following this site. I want to add an extra field email along with those available in model. I have

form.py

from django import forms from django.forms import ModelForm import django.forms

from new_db.models import Author,Publisher,Book

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)  

views.py

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

and the error I encountered is

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

Upvotes: 1

Views: 5974

Answers (1)

karthikr
karthikr

Reputation: 99680

You have a typo

class meta:

Should be

class Meta:

Note the case.

More here https://docs.djangoproject.com/en/dev/topics/db/models/#meta-inheritance

Upvotes: 12

Related Questions