i am trying to update a record from mysql database. Following is my update func.
def update(request,id):
user=Login.objects.get(id=id)
form=LoginForm(request.POST, instance=user)
if form.is_valid():
print("Form is valid.")
form.save()
return redirect("/show")
else:
print("Form is In-valid.")
return render(request,"edit.html",{"qs":user})
in the terminal it is saying that form is In-valid as i printed in the command of else part so this means the form that i created above is not valid dont know what to do kindly help.
dont pass the user instance to the form creation, form=LoginForm(request.POST or None). Try this
- scott 4 years, 10 months agoBy doing this wont be the values of the fields that needed to be save would be lost ?
- moazamrana22 4 years, 10 months agoafter form valid add the user . It should work. like form = form(commit=false
form.user = user
form.save()
. try something like this
As we are not getting any update on this ticket, as you raised as HIGH priority. Hopefully you have resolved the issue. So we go ahead and close the ticket. In case if doesnt work , then submit the new one.
- Vengat
Acknowledged