def form_valid(self, form):
        self.object = form.save(commit=False)

        try:
            self.object = self.pre_save(self.object)
            self.save(self.object)
            self.object = self.post_save(self.object)

            messages.success(self.request, self.derive_success_message())
            if self.request.META not in 'HTTP_X_FORMAX':
                return HttpResponseRedirect(self.get_success_url())
            else:
                response = self.render_to_response(self.get_context_data(form=form))
                response['REDIRECT'] = self.get_success_url()
                return response

        except IntegrityError as e:
            message = str(e).capitalize()
            errors = self.form._errors.setdefault(forms.forms.NON_FIELD_ERRORS, forms.utils.ErrorList())
            errors.append(message)
            return self.render_to_response(self.get_context_data(form=form))
dataset/ETHPy150Open nyaruka/smartmin/smartmin/views.py/SmartModelFormView.form_valid/swapped operands of `not in`