Django inlineformset - 'CapForm'对象没有属性'cleaning_data'

时间:2016-10-16 08:15:10

标签: python django

我面临属性错误,

'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)

任何人都可以帮我指出问题所在

1 个答案:

答案 0 :(得分:0)

你在SesForm上调用了is_valid,但在CapFormSet上没有调用。