'New bid is not updating to show the Users input (amount) Django

Trying to create an e-bay like platform where users can select an item and bid on it, the bid amount should update to the latest valid bid inputted by a user.

Currently, the amount is not updating to show that a user has made bid, it shows me the pop up message of

                messages.success(request, 'Successfully added your bid')

but does not update this part of the bids showing or the count increasing

 <p>Current price: ${{ detail.current_bid }}</p>

Could you please give me an insight of what is causing this?

MODELS.PY


class Auction(models.Model):
    title = models.CharField(max_length=25)
    description = models.TextField()
    current_bid = models.IntegerField(null=False, blank=False)
    image_url = models.URLField(verbose_name="URL", max_length=255, unique=True, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    category = models.ForeignKey(Category, max_length=12, null=True, blank=True, on_delete=models.CASCADE)
    is_active = models.BooleanField(default=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return f"(self.title)"

    def no_of_bids(self):
        return self.bidding.all().count()
    
    def current_price(self):
        if self.no_of_bids() > 0:
            return self.bidding.aggregate(Max('new_bid'))['new_bid__max']
        else: 
            return self.current_bid

    def current_winner(self):
        if self.no_of_bids() > 0: 
            return self.bidding.get(new_bid=self.current_price()).user
        else: 
            return None

    class Meta:
        ordering = ['-created_at']

class Bids(models.Model):
    auction = models.ForeignKey(Auction, on_delete=models.CASCADE, related_name='bidding', null=True)
    user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='bidding')
    new_bid = models.DecimalField(max_digits=8, decimal_places=2)
    done_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.new_bid)

    class Meta:
        ordering = ['auction', '-new_bid']

VIEWS.PY

def listing_detail(request, listing_id):
    try:
        detail = get_object_or_404(Auction, pk=listing_id)
    except Auction.DoesNotExist:
        messages.error(request, "This is not available") 
        return HttpResponseRedirect(reverse("index"))

    bid_count = Bids.objects.filter(auction=listing_id).count()
    bid_form= BidForm()     

    if request.method == 'POST':
        comment_form = CommentForm(request.POST)

        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.auction = detail
            new_comment.save()

            return redirect('listing_detail', listing_id=listing_id)

        else:
            comment_form = CommentForm()
    else:
        comment_form = CommentForm()

    context = {'detail': detail,
                'bid_count': bid_count, 
                'bid_form': bid_form,
                'comment_form': comment_form
                } 

    return render(request, 'auctions/details.html', context)

@login_required
def make_bid(request, listing_id):
    if request.method == 'POST':
        auction = Auction.objects.get(pk=listing_id)
        bid_form = BidForm(request.POST)
        if bid_form.is_valid():
            bid_form.instance.user = request.user
            bid_form.instance.item = auction

            if bid_form.instance.new_bid > auction.current_price():
                bid_form.save()
                messages.success(request, 'Successfully added your bid')
                return HttpResponseRedirect(reverse("listing_detail", args=(listing_id,)))
            else:
                messages.error(request, 'Bid price lower than current price, increase bid please')
                return HttpResponseRedirect(reverse("listing_detail", args=(listing_id,)))


        else:
            context = {
                'bid_form': bid_form
                }
            
            return render(request, 'auctions/details.html', context)  
                
    return render(request, 'auctions/details.html', {'bid_form': bid_form})  

FORMS.PY

class BidForm(forms.ModelForm):

    class Meta:
        model = Bids
        fields = ['new_bid']
        labels = {
            'new_bid': ('Bid'),
        }

DETAILS.PY

                            <p>Current price: ${{ detail.current_bid }}</p>
                            <hr>
                            <p>{{ detail.no_of_bids }} bids so far</p>
                            <hr>

                            <form action="{% url 'make_bid' detail.id %}" method="post">
                                {% csrf_token %}
                                {{ bid_form }}
                                <input type="submit" class="btn btn-primary btn-block mt-3" value="Place bid">
                            </form>

URL.PY

    path("make_bid/<int:listing_id>", views.make_bid, name="make_bid"),


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source