我的m.export(...)
views.py
我的class AccountListView(ListView):
context_object_name = 'accounts'
model = models.Account
class AccountCreateView(CreateView):
fields = ('foo', 'bar')
model = models.Account
forms.py
我的class AccountForm(forms.ModelForm):
foo = forms.ModelDecimalField()
bar = forms.ModelDateField()
def clean_foo(self):
foo_passed = self.cleaned_data.get("foo")
if foo_passed > 1000:
raise forms.ValidationError("Sorry, Maximum is 1000.")
return foo_passed
template.html
在我上面的代码中,我试图验证输入,如果值大于1000会引发错误。但它不起作用,我想念它。
答案 0 :(得分:2)
您需要告诉您的观点使用您的表单类:
class AccountCreateView(CreateView):
fields = ('foo', 'bar')
model = models.Account
form_class = AccountForm