2013-04-17 56 views
0

我想創建一個從我的模型繼承的表單,但它不工作,我找不到原因。從模型擴展的Django表單不起作用

它不會拋出任何異常,但不會顯示指定的字段。

models.py

class Picture(models.Model): 
    picture = models.ImageField(upload_to='/') 
    name = models.CharField(max_length=30) 
    owner = models.ForeignKey(Artist) 
    date = models.DateField() 
    description = models.CharField(max_length=1000) 
    width = models.IntegerField(max_length=9) 
    height = models.IntegerField(max_length=9) 
    sold = models.BooleanField(default=False) 
    added = models.DateTimeField(auto_now_add=True) 
    active = models.BooleanField(default=False) 
    genres = models.ManyToManyField(Genre) 
    def __unicode__(self): 
     return u'%s from %s by %s' % (self.name, self.date, self.owner) 

forms.py

class PictureForm(forms.Form): 
    class Meta: 
     model = Picture 
     fields = ('picture', 'name', 'date', 'description', 'width', 'height') 

我缺少的東西,還是有一個普遍的錯誤?

回答

2

您使用forms.Formforms.ModelForm

class PictureForm(forms.ModelForm): 
    class Meta: 
     model = Picture 
     fields = ('picture', 'name', 'date', 'description', 'width', 'height')