Django why inline formset validation fails? -
view
def add_poll_checkbox(request): new_poll = poll.objects.create(author=request.user) if request.post: form = addpoll(request.post, instance=new_poll) if form.is_valid(): poll = form.save(commit=false) poll.author = request.user poll.poll_type = 1 formset = choiceformset(request.post, instance=poll) if formset.is_valid(): poll.save() formset.save() return httpresponseredirect('/admin/teacher/') else: formset = choiceformset(instance=new_poll) else: form = addpoll(instance=new_poll) formset = choiceformset(instance=new_poll) return render_to_response('add_poll_checkbox.html', {'form': form, 'formset': formset}, context_instance=requestcontext(request))
form
class addpoll(forms.modelform): class meta: model = poll choiceformset = inlineformset_factory(poll, choice, extra=2, can_delete=false)
please tell me wrong in code? can't save form , formset.
Comments
Post a Comment