我有以下型号:
class comment(models.Model):
userid=models.CharField(max_length=140)
apparelid=models.IntegerField(blank=True)
desc=models.TextField(blank=True)
def __unicode__(self):
return self.userid
形式 :
class commentForm(ModelForm):
class Meta:
model=comment
exclude=('userid','apparelid',)
并查看如下:
def comment(request,title_id):
if request.method=='POST':
form=commentForm(request.POST)
if form.is_valid():
new=form.save(commit=False)
new.userid=request.user.username
new.apparelid=title_id
new.save()
return HttpResponseRedirect('/')
else:
form=commentForm()
template=loader.get_template('apple3/comment.html')
context=RequestContext(request,{
'form':form,
}
)
return HttpResponse(template.render(context))
每当我打开包含上述表单的页面时,它都会显示如下错误:
Exception Type: AttributeError
Exception Value: 'function' object has no attribute 'objects'