3
我正在使用modelform來顯示模型中只有一部分字段。當表單被提交時,它失敗了form.is_valid(),但form.errors是空的。我不想在這裏展示我所有的代碼,但下面是一個示例:modelform failed is_valid w/o setting form.errors
式樣和
class Videofiles(models.Model):
active = models.CharField(max_length=9)
filenamebase = models.CharField(max_length=180, primary_key=True, db_column='FilenameBase')
program = models.CharField(max_length=60, db_column='Program')
displayname = models.CharField(max_length=150, db_column='DisplayName')
description = models.TextField(db_column='Description', blank=True)
tagskeywords = models.TextField(db_column='TagsKeywords', blank=True)
class Meta:
db_table = u'legacyTable'
class VideoFilesForm(ModelForm):
filenamebase = forms.CharField(max_length=30)
displayname = forms.CharField(max_length=30)
description = forms.CharField(max_length=30, required=False)
tagskeywords = forms.CharField(max_length=60, required=False)
class Meta:
model=Videofiles
fields=['filenamebase','displayname','description','tagskeywords']
查看
def editClip(request, clipId):
clip = Videofiles.objects.get(filenamebase=clipId)
form = VideoFilesForm(instance=clip)
if request.method == 'POST':
if 'save' in request.POST:
if form.is_valid():
form.save()
else:
print form.errors
return render_to_response('legacyDB/edit_clip.html',locals())
我發現,由於某種原因,我的形式不綁定。研究爲什麼是這樣。 – jamida 2010-07-24 18:48:22