Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ModelForm has no model class specified

I am trying to use ModelForm:

from django.db import models
from django.forms import ModelForm

class Car(models.Model):
    carnumber = models.CharField(max_length=5)

    def __unicode__(self):
        return self.carnumber

class PickForm(ModelForm):
    class Meta:
        Model = Car`

I have checked this and I cannot find my error. When I call the view in a browser, it gives me the following error:

ModelForm has no model class specified

I have tested the view that calls the model with simple "foo bar" code at the same URL, but when I try this code, I get the class error above.

like image 342
dpbklyn Avatar asked Jan 25 '12 23:01

dpbklyn


3 Answers

It should be model instead of Model (and without the trailing `, but I guess that's a typo):

class PickForm(ModelForm):
    class Meta:
        model = Car
like image 57
Jan Pöschko Avatar answered Nov 12 '22 14:11

Jan Pöschko


my error was because I wrote meta instead of Meta

like image 37
Moe Roddy Avatar answered Nov 12 '22 16:11

Moe Roddy


Just do this method your page will run:

class PickForm(ModelForm):
  class Meta:
    model = Car
    fields = "__all__"
like image 7
raja manikkam Avatar answered Nov 12 '22 16:11

raja manikkam