def delete(request, id):
destroy = Appointment.objects.get(id=id)
if destroy.status == "Done" or "Missed" or "Pending" and request.session["userid"] == destroy.user.id:
destroy.delete()
return redirect('/update/table')
So my delete function works.
However the code doesn't do what I'm wanting it to exactly. I want to do a triple check of the 3 strings("Done", "Missed" and "Pending") individually with the "and request.session["userid"] == destroy.user.id:"
If I put:
if destroy.status == "Pending" and request.session["userid"] == destroy.user.id:
destroy.delete()
Then it will only delete the object on the table I have created which has "Pending" in its status. So that works good. However...
If I put:
if destroy.status == "Pending" or "Done" and request.session["userid"] == destroy.user.id:
destroy.delete()
If I click my delete button on what ever has "Pending" it deletes, great. If I click on anything that has "Done", deleted, great. However if I click my delete button on anything that has "Missed" it still deletes it?? So my code is redundant by adding the 3rd string "Missed". I can't wrap my brain right now on why it still deletes the "Missed" if I leave it out.
How do I clean this code up so it does what I'm wanting it to do.
Aucun commentaire:
Enregistrer un commentaire