class Author(models.Model): name = ... title = ... year = ... class PartialAuthorForm(ModelForm): class Meta: model = Author fields = ('name','title') def __init__(self,*args,**kwargs): self.Meta.fields += ('year',)
执行此操作的方法是手动将自己添加到self.fields中:
def __init__(self,**kwargs): super(PartialAuthorForm,self).__init__(*args,**kwargs) self.fields['year'] = forms.CharField(whatever)