I want to update records, I use View instated of UpdateView, is this right way ? can anyone tell me, is this right way or wrong?

10 views
Skip to first unread message

Amitkumar Satpute

unread,
Jan 15, 2018, 12:23:16 PM1/15/18
to Django users



  1. views.py
  2. -------------------------------------------
  3. class UpdateUser(View):
  4. def post(self,request,pk):
  5. user=get_object_or_404(User,pk=pk)
  6. userinfo=get_object_or_404(UserCreation,user=user)
  7. user_form=UserUpdateForm(request.POST,instance=user)
  8. user_creation_form=UserCreationForm(request.POST,instance=userinfo)
  9. if user_form.is_valid() and user_creation_form.is_valid():
  10. user=user_form.save(commit=False)
  11. user.save()
  12. user_create=user_creation_form.save(commit=False)
  13. user_create.modified_date()
  14. user_create.save()
  15. return redirect('adminaccount:add_user')
  16. return render(request,'adminaccount/add_new_user.html',{'user_form':user_form,'user_creation_form':user_creation_form,'btn':'Update'})
  17.     def get(self,request,pk):
  18. user=get_object_or_404(User,pk=pk)
  19. userinfo=get_object_or_404(UserCreation,user=user)
  20. user_form=UserUpdateForm(instance=user)
  21. user_creation_form=UserCreationForm(instance=userinfo)
  22. return render(request,'adminaccount/add_new_user.html',{'user_form':user_form,'user_creation_form':user_creation_form,'btn':'Update'})

Matemática A3K

unread,
Jan 16, 2018, 9:26:28 PM1/16/18
to django...@googlegroups.com
Does it work?

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef2efcff-ed34-4fd6-8764-6af4aba4ad5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages