[Answered ]-Django: Update object from view, with no model or template

2๐Ÿ‘

โœ…

I sort of solved my problem. I gave up on using a class based view and used the following function instead:

def SynonymReset(request, user_id, pk):
  """(re)sets the Synonym.value to the value of Synonym.key"""

  #Get relevant variables
  currentuser = User.objects.get(id=request.user.id)
  currentsynonym = Synonym.objects.get(id = pk)

  #(re)set object & save
  currentsynonym.value = currentsynonym.key
  currentsynonym.save()

  #Return to the listview.
  return redirect('synonym_list', user=current_user)

This way the value is reset, without going to a seperate webpage. I still hope to one day find out how to do this in a class based view. But for now this will suffice.

Leave a comment