I am trying to update a record in Database using Django but it adds the same record again. How i can fix it? code is given below.
def update(request, id):
book = tblbook.objects.get(id=id)
form = tblbook(BookID = book.BookID, BookName=book.BookName, Genre=book.Genre,Price=book.Price)
form.save()
return redirect("/show")
2
Answers
your object is in book, as you have used get() method
now should do something like this
accotding to your snippet it would be like this
You can also use update() method with filter() method, and it would look something like this
Your code is inserting new record to DB.
Suppose you want to update the book name, then below code might help-
similarly, you can update other fields as well