python - Using CBV form_invalid() method to update Model object -


I want to update existing object in the model. But I am using form_invalid (self, form) for this.

  ** views.py ** class SomeClassView (UpdateView): model = some form_class = SomeForm template_name = 'some.html' DEF form_inville (self, form): something.bjects.jet ( ID = Sway Kevar ['PK']). Update (** form.ScaledData) Returns HTTPPRPSPoint Redirect (AutoRequest. POST [Redirect_url ']) ** urls.py ** url (r' ^ Edit / (? P & lt; pk & gt; \ d + ) / $ ', SomeclassView.as_view (), name =' edit '),   
  AttributeError at / edit / 1 / 'some' objects have no attributes 'Update'  

< Div Class = "post-text" itemprop = "text">

This is because get () returns no query, instead it gives an example of this model.

Try to change

  some.bjects. Gat (id = self.kwargs ['pk']). With update (* * Form.cleaned_data)  

  some.objects.filter (id = self.kwargs ['pk']). Update (** form .cleaned_data)  

Read more for more information.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -