手冊例如:http://docs.djangoproject.com/en/1.0/topics/forms/formsets/#formset-validation(我使用Django 1.0.3對谷歌的App Engine運行)這是Django formset驗證中的錯誤嗎?
代碼:
from django import forms
from django.forms.formsets import formset_factory
class ArticleForm1(forms.Form):
title = forms.CharField()
pub_date = forms.DateField()
class ArticleForm2(forms.Form):
title = forms.CharField()
class ArticleForm3(forms.Form):
title = forms.CharField()
pub_date = forms.CharField()
ArticleFormSet1 = formset_factory(ArticleForm1)
ArticleFormSet2 = formset_factory(ArticleForm2)
ArticleFormSet3 = formset_factory(ArticleForm3)
data = {
'form-TOTAL_FORMS': u'2',
'form-INITIAL_FORMS': u'0',
'form-0-title': u'',
'form-0-pub_date': u'16 June 1904',
'form-1-title': u'', # <-- this title is missing but required
'form-1-pub_date': u'16 June 1904', # <-- this date is missing but required
}
formset = ArticleFormSet1(data)
print "Should be False: %s" % formset.is_valid()
formset = ArticleFormSet2(data)
print "Should be False: %s" % formset.is_valid()
formset = ArticleFormSet3(data)
print "Should be False: %s" % formset.is_valid()
輸出:
$ .../ActiveStatePython2.5/python.exe formset_bug.py
Should be False: False
Should be False: True
Should be False: False
的ActiveState的Python 2.5.4.4 ,Django 1.0.3 final。
它看起來好像只在一個CharField(但是2個CharFields或一個CharField和一個DateField工作)的情況下不能驗證。
我谷歌搜索這樣的錯誤,找不到任何東西。我還沒有試過Django 1.1,但現在在GAE上使用1.0更容易。