Friday, October 24, 2014

"autocommit cannot be used inside a transaction" error: trying to use a custom form with a CreateView

Hi,

I get an "autocommit cannot be used inside a transaction" error at the ins.save() line in the model form.

I am trying to use a custom form for a CreateView.

What does this error exactly mean?
Why can't I save the instance?

Thanks


class MyModelForm(forms.ModelForm):
 
 
class Meta:
   model
= MyModel
   fields
= ['field1']

 
def save(self, commit=True):
   ins
= super(MyModelForm, self).save(commit=False)
   ins
.set_some_variables()
   
if commit:
     ins
.save()
   
return ins

class CustomCreateView(SuccessMessageMixin, CreateView):
  form_class
= MyModelForm
  template_name
='template.html'
  success_message
= _('Congrats.')

 
def get_success_url(self):
   
return reverse('same_view')



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d149137c-cdd8-4aaa-bf64-024df2583d89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment