1、直接创建
from django.forms import ModelForm
class TestModelForm(ModelForm): class Meta: model = self.model_class #表所对应的类 fields = "__all__"
2、通过“type”创建
from django.forms import ModelForm meta = type(‘Meta‘,(object,),{‘model‘:self.model_class,‘fields‘:‘__all__‘}) TestModelForm = type(‘TestModelForm‘,(ModelForm,),{‘Meta‘:meta})