django-bootstrap-modal-forms
django-bootstrap-modal-forms copied to clipboard
FormValidationMixin shadows setting of self.object (defined in BaseCreateView)
I was tracking down, why self.object wasn't available in my view (deriving from BSModalCreateView) during get_success_url(), as in Django's BaseCreateView.form_valid(form) the default behaviour is to set self.object = form.save().
However, in django-bootstrap-modal-forms form_valid is shadowed by FormValidationMixin which currently fails to either
- replicate the behaviour or
- call the super() function.
Having the same issue, found any workarounds yet? For now I have to revert back to an older version.
Hi, comrades. i'm having the same issue, but my solution is inherit mixin FormValidationMixin, based on this post mr' s Sisch. As an example:
from bootstrap_modal_forms.mixins import PassRequestMixin, FormValidationMixin, is_ajax
class MyFormValidationMixin(FormValidationMixin):
def form_valid(self, form):
isAjaxRequest = is_ajax(self.request.META)
asyncUpdate = self.request.POST.get('asyncUpdate') == 'True'
if isAjaxRequest:
if asyncUpdate:
self.object = form.save() #here changed for solution
return HttpResponse(status=204)
self.object = form.save() #here changed for solution
messages.success(self.request, self.get_success_message())
return HttpResponseRedirect(self.get_success_url())
class OrderCreateOperatorView(LoginRequiredMixin, PassRequestMixin, MyFormValidationMixin, CreateView):
template_name = 'orders/create_order_operator.html'
form_class = OrderCreateOperatorForm
success_message = 'Заказ оформлен'
success_url = reverse_lazy('contacts:n_contacts')
def get_success_url(self):
return reverse_lazy('orders:OrderDetailView', kwargs={'pk': self.object.pk})
It gives control over the object by self.object