django - Can't override post method UpdateView -


i try override post method of generic.updateview add few forms other model. without overriding post working fine.

class desktopview(loginrequiredmixin, updateview):     model = weddyuser     context_object_name = 'weddyuser'     slug_field = 'username'     form_class = weddyuserform      def get_context_data(self, **kwargs):         context = super(desktopview, self).get_context_data(**kwargs)         if self.request.user.is_vendor:             if 'form' not in context:                 context['form'] = self.form_class(self.request.get, instance=self.request.user)             context['vendor'] = vendor.objects.get(id=self.request.user.id)         else:             context['plainuser'] = plainuser.objects.get(id=self.request.user.id)         return context      def get(self, request, *args, **kwargs):         self.object = self.get_object()         c = {}         c.update(csrf(request))         user = request.user         if self.kwargs['slug'] == request.user.username:             if user.is_vendor:                 return render_to_response('user/vendor_edit_profile.html', self.get_context_data(),                                       requestcontext(request, c))             return render_to_response('user/user_edit_profile.html', self.get_context_data(),                                   requestcontext(request, c))         return httpresponse(status=404)      def post(self, request, *args, **kwargs):         self.object = self.get_object()         c={}         c.update(csrf(request))         form = self.form_class(request.post)         if form.is_valid():             print ('its work')             form.save()             return render_to_response('user/vendor_edit_profile.html', self.get_context_data(form=form),                                       requestcontext(request, c))         else:             print(form.errors)             return render_to_response('user/vendor_edit_profile.html', self.get_context_data(form=form),                                       requestcontext(request, c)) 

everytime invalid form - "required field"

you shouldn't overriding or post here. in case, need override form_valid logic in post, , get_tempmlate logic in get.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -