for my django project I have a page which allows a user to edit their listing, for this I am adding a check that ensures the person opening the page is the owner of the listing. However the if statement I have put in always returns true no matter what, even if I change what it is checking to a totally unrelated object. I even changed it from != to == and it always returned true, does anyone know what is going on here?
@login_required(redirect_field_name='login')
def editlisting(request, pk):
post = JobListing.objects.get(pk=pk)
if request.user != post.user:
print("THIS WORKS") #This is for debugging
print(request.user) #This is for debugging
print(post.user) #This is for debugging
return redirect("index")
if request.method == "POST":
form = JobListingForm(request.POST, instance=post)
if form.is_valid():
profile = form.save(commit=False)
profile.user = request.user
profile.save()
return redirect('index')
else:
form = JobListingForm(instance=post)
context = {
"form": form
}
return render(request, "editlisting.html", context)
Any help appreciated!
Aucun commentaire:
Enregistrer un commentaire