I have a class-based view called OrganizationsCreateView
that includes a formset attached to a model form as an instance variable of that form. This works fine when the user enters data -- a new object is created fine. When the user wants to add additional rows to the formset, I have a submit button that triggers a conditional in the CreateView's post method:
def post(self,request,*args,**kwargs):
if 'add_email' in request.POST:
cp = request.POST.copy()
cp['emails-TOTAL_FORMS'] = int(request.POST['emails-TOTAL_FORMS']) + 1
self.initial_emails = cp
return super(OrganizationsCreateView,self).post(request,*args,**kwargs)
This adds rows just fine, but unfortunately it also adds a new object each time the user adds a new row. How/where should I short-circuit this object adding behavior?