我面临属性错误,
'CapForm' object has no attribute 'cleaned_data'
这是我的帖子方法
def post(self,request,*args,**kwargs):
user = request.user.id
form = SesForm(request.POST,request.FILES,user=request.user)
if form.is_valid():
frm = form.save(commit=False)
frm.user = request.user
frm.status = False
obj = frm.save()
cap_formset = CapFormSet(request.POST)
cap_formset.instance = frm # Tried obj also it throws - 'NoneType' object has no attribute '_state'
cap_formset.save()
我的表格
class CapForm(forms.ModelForm):
title = forms.CharField(label=_('Cap'))
class Meta:
model = Cap
fields = ('title',)
def __init__(self,*args,**kwargs):
super(CapForm,self).__init__(*args,**kwargs)
for name, field in self.fields.iteritems():
field.widget.attrs.update({'class': 'form-control', 'placeholder': field.label})
Formset声明
CapFormSet = inlineformset_factory(Ses, Cap, form=CapForm, extra=1, can_delete=True)
任何人都可以帮我指出问题所在
答案 0 :(得分:0)
你在SesForm上调用了is_valid
,但在CapFormSet上没有调用。