I'm trying to change a BooleanField from a model in django, using the post method activated with a button but is not working, the post method from the button is working but the function is not doing what it should do. When i change the boolean value in the admin tool it's work, i think probable the problem is in the function but i don't know whats is the problem.
This is my function:
def close(request, listing_id):
listing = Listing.objects.get(id=listing_id)
if request.method == "POST":
listing.active = False
listing.save()
messages.success(request, 'You closed the Auction!')
return redirect(reverse("listing", args=[listing_id]))
The BooleanField whats i want to change it's call "active" (true by default).
and this is the button:
<form action="{% url 'close' listing.id %}" method="post" >
{% csrf_token %}
<button type="submit" name="action" value="close" class="btn btn-warning mb-3">Close Auction</button>
</form>