django管理表单。用于空白IntegerField的ModelForm验证

时间:2019-07-03 06:25:45

标签: python django django-forms

如何在Django管理员中进行设置,以便在单击Forms.IntegerField为空白以返回验证错误时单击保存。当前,如果您保存模型,它将仍然接受交易。

有什么建议吗?

forms.py`

class CarInlineForm(forms.ModelForm):
    car_type = forms.CharField(disabled=True)
    car_qty = forms.IntegerField(min_value=1)

    class Meta:
        model = Car
        exclude = ['created']

admin.py

class CarInline(admin.TabularInline):
    model = CarOrderItem
    extra = 1
    max_num = 1
    form = CarInlineForm
    exclude = [
        'created',
    ]


class CarAdmin(admin.ModelAdmin):
    inlines = [CarInline]

0 个答案:

没有答案