Django:ModelForm在验证时没有调用clean_xxxx?

时间:2016-10-29 08:49:41

标签: django django-forms

models.py

class OrderImage(TimeStampedModel):
    img = models.ImageField()
    name = models.CharField(max_length=40)

forms.py

class OrderImageForm(forms.ModelForm):

class Meta:
    model = OrderImage
    fields = ['img', 'name',]

def clean_name(self):
    print("name")

def clean_img(self):
    print("img")

我用clean_img

打破from IPython import embed; embed();

我测试了一下,

def test_a(self):
    form = OrderImageForm({
        'img':'b',
        'name':'a'
    })
    form.is_valid()

当我测试时,它只打印name ....

为什么会这样?

0 个答案:

没有答案