# How to get highest bid in an auction bidding site Django

**URL:** <https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382>\
**Category:** Forms & APIs\
**Created:** [February 28, 2022, 12:59pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382 "2022-02-28T12:59:07Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 10, 2022, 5:01pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/21 "2022-03-10T17:01:26Z")

</div>

> [@KenWhitesell](#):
>
> What query could you write to obtain the `current_bid` ?

current\_bid = Auction.objects.get('current\_bid)

Possible?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 10, 2022, 5:02pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/22 "2022-03-10T17:02:23Z")

</div>

I suggest you try that in the Django shell to see what you get.

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 10, 2022, 5:12pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/23 "2022-03-10T17:12:21Z")

</div>

> [@KenWhitesell](#):
>
> you’ll need to query it from the database

Didn’t work, got

# ValueError at /make\_bid/2

too many values to unpack (expected 2)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 10, 2022, 5:14pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/24 "2022-03-10T17:14:01Z")

</div>

What didn’t work? (You obviously jumped way ahead of where I was with my last response, so I don’t know what you just tried.)

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 10, 2022, 5:14pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/25 "2022-03-10T17:14:55Z")

</div>

> [@Theresa-o](#):
>
> current\_bid = Auction.objects.get('current\_bid)
> 
> Possible?

Tried this

```auto
    def clean_new_bid(self):
        new_bid = self.cleaned_data['new_bid']
        current_bid = Auction.objects.get('current_bid')

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 10, 2022, 5:22pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/26 "2022-03-10T17:22:21Z")

</div>

Ok, I suggested you try out that query in the Django shell, not by updating your view with it.

Had you tried just that query in the shell, you would have seen that it would not retrieve the information that you need.

Back in your post at [How to get highest bid in an auction bidding site Django - #19 by Theresa-o](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/19) you show a query on the Auction model.

The query you need to write needs to get the proper instance of that model, and _then_ access the `current_bid` field of that model.

If necessary, review the docs at:

- [Making queries | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/db/queries/)
  - [Retrieving Objects](https://docs.djangoproject.com/en/4.0/topics/db/queries/#retrieving-objects)
  - [Retrieving a single object](https://docs.djangoproject.com/en/4.0/topics/db/queries/#retrieving-a-single-object-with-get)

Along with the examples at [Writing your first Django app, part 3 | Django documentation | Django](https://docs.djangoproject.com/en/4.0/intro/tutorial03/).

And if you’re not familiar with the Django shell, you should become familiar with it - see [Writing your first Django app, part 2 | Django documentation | Django](https://docs.djangoproject.com/en/4.0/intro/tutorial02/#playing-with-the-api).

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 10, 2022, 8:32pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/27 "2022-03-10T20:32:15Z")

</div>

> [@Theresa-o](#):
>
> `current_bid = Auction.objects.get('current_bid')`

current\_bid = Auction.objects.get(current\_bid=current\_bid)

On my windows shell ‘NameError: name ‘current\_bid’ is not defined’

I don’t know what to do at this point.

Tried .filter() but still same

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 10, 2022, 11:45pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/28 "2022-03-10T23:45:32Z")

</div>

In your view, you have:

> [@Theresa-o](#):
>
> ```auto
> def make_bid(request, listing_id):
> auction = Auction.objects.get(pk=listing_id)
> 
> ```

So in this case, you’re retrieving a specific Auction object - the one for which you want to submit a bid - and likely the one from which you want to access the current bid.

Question 1: If you have an object of type Auction named `auction`, how do you access the `current_bid` value in that instance?

Now, you have access to the `listing_id` in the view, which doesn’t help you in the form. You still need to pass either the `listing_id`, or the Auction object itself, into the form.

You have a couple different ways of accomplishing that. My personal preference for that would be to pass it as a named parameter to the form.

In the view:

```auto
bid_form = BidForm(request.POST, auction=auction)

```

This passes a new named parameter into the form named `auction`.

So then you need to retrieve this parameter in the form. This can be done by adding an ` __init__ ` method to the form.  
Example:

```auto
def __init__ (self, *args, **kwargs):
    self.auction = kwargs.pop('auction', None)
    super(). __init__ (*args, **kwargs)

```

You then have a variable named `auction` (accessed as `self.auction` in that class) that accesses whatever value was passed into the form constructor.

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 14, 2022, 1:40pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/29 "2022-03-14T13:40:37Z")

</div>

Hi Ken, thank you for the help so far.

> [@KenWhitesell](#):
>
> So then you need to retrieve this parameter in the form. This can be done by adding an ` __init__ ` method to the form.  
> Example:
> 
> ```auto
> def __init__ (self, *args, **kwargs):
> self.auction = kwargs.pop('auction', None)
> super(). __init__ (*args, **kwargs)
> 
> ```

I have been reading up on the ` __init__ ` method (this is my first time seeing it),

> [@KenWhitesell](#):
>
> You then have a variable named `auction` (accessed as `self.auction` in that class) that accesses whatever value was passed into the form constructor.

So, I searched online for how to access the starting\_bid using ‘self.auction’ and I have so far tried this (referencing this [python - get request data in Django form - Stack Overflow](https://stackoverflow.com/questions/1202839/get-request-data-in-django-form));

```auto
    def clean_new_bid(self):
        new_bid = self.cleaned_data['new_bid']
        starting_bid = self.auction.starting_bid

```

This throws the below error

# AttributeError at /make\_bid/2

‘NoneType’ object has no attribute ‘starting\_bid’

I also saw a different post on how to reference an init variable [Django ModelForms \_\_init\_\_ kwargs create and update - Stack Overflow](https://stackoverflow.com/questions/21119494/django-modelforms-init-kwargs-create-and-update) and [Pass data to django form's field clean method - Stack Overflow](https://stackoverflow.com/questions/24251141/pass-data-to-django-forms-field-clean-method)

```auto
    def clean_new_bid(self):
        new_bid = self.cleaned_data['new_bid']
        starting_bid = Auction.objects.get(starting_bid = self.auction)

```

This threw this error

# TypeError at /make\_bid/2

Field ‘starting\_bid’ expected a number but got \<Auction: Brain/Cloud\>.

Brain/Cloud is the name/title of my post.

How do I reference self.auction in this scenario to get the starting\_bid to use in the clean function to compare with new\_bid?

I really did try to research in order to come up with a solution by myself but I’ve been stuck since and would appreciate your input. Thank you.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 14, 2022, 1:55pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/30 "2022-03-14T13:55:36Z")

</div>

I need to see your current view and form for this. I know there’s a lot of work that has been done, and I can’t piece together what the current code looks like from the various responses here.

These two parts (view and form) work together. The view needs to pass _either_ the auction object, _or_ the id for the auction object to the form. What the view passes to the form will determine what the form needs to do with it.

The `NoneType` error is an indication that you are not passing (or retrieving, depending) the auction object to the form from the view.

The TypeError is telling you that you’re trying to assign the complete Auction object to `starting_bid`, not the numeric field. (Also, I have a feeling that your query is wrong - you want to do a get based on the key, not the value of the bid. It appears to me that you’re mixing up the process of retrieving an object and getting the values _from_ that object.)

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 14, 2022, 2:01pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/31 "2022-03-14T14:01:09Z")

</div>

This is the what I have so far

VIEWS.PY

```auto
def make_bid(request, listing_id):
    auction = Auction.objects.get(pk=listing_id)
    bid_item = Bids.objects.filter(auction=auction).order_by('-new_bid').first()
    

#if theres no bid available, use starting bid, if available, update to the latest bid

    if bid_item == None:
        bid = auction.starting_bid
    else:
        bid = bid_item.new_bid

    if request.method == 'POST':
        bid_form = BidForm(request.POST, auction=auction)
        if bid_form.is_valid():
            user = request.user 
            bid_count = Bids.objects.filter(auction=listing_id).count()
            new_bid = request.POST['new_bid']
            Bids.objects.create(auction=auction, user = user, new_bid = new_bid)
            messages.success(request, 'Successfully added your bid')
            return HttpResponseRedirect(reverse("listing_detail", listing_id=listing_id))

        else:
            bid_form = BidForm(request.POST)
            context = {
                "bid_form": bid_form,
                "bid": bid,
                "bid_item": bid_item,
                "auction": auction
                } 

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

```

FORMS.PY

```auto
class AuctionForm(forms.ModelForm):
    
    class Meta:
        model = Auction
        fields = ['title', 'description', 'starting_bid']

        widgets = {
            'title': forms.TextInput(attrs={'class': 'form-control'}),
            'description': forms.Textarea(attrs={'class': 'form-control'}),
            'starting_bid': forms.NumberInput(attrs={'class': 'form-control'}),
        }

class BidForm(forms.ModelForm):

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

    def __init__ (self, *args, **kwargs):
        self.auction = kwargs.pop('auction', None)
        super(). __init__ (*args, **kwargs)

    def clean_new_bid(self):
        new_bid = self.cleaned_data['new_bid']
        starting_bid = Auction.objects.get(starting_bid = self.auction)   

        if new_bid <= starting_bid:
            raise ValidationError("New bid must be greater than the previous bid")
                
        return new_bid

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 14, 2022, 2:29pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/32 "2022-03-14T14:29:12Z")

</div>

From this line in the view:

> [@Theresa-o](#):
>
> ```auto
> bid_form = BidForm(request.POST, auction=auction)
> 
> ```

you’re passing an actual Auction object into the form.

If I have an object of type `Auction` named `auction`, how do I access the `starting_bid` field of `auction`?

Once you understand that, then you can change:

> [@Theresa-o](#):
>
> `starting_bid = Auction.objects.get(starting_bid = self.auction)`

to the appropriate syntax.

(If necessary, review page 2 of the tutorial, including the section at [Playing with the API](https://docs.djangoproject.com/en/4.0/intro/tutorial02/#playing-with-the-api).

Also, from your view:

> [@Theresa-o](#):
>
> ```auto
> if bid_form.is_valid():
> user = request.user
> *** bid_count = Bids.objects.filter(auction=listing_id).count()
> *** new_bid = request.POST['new_bid']
> *** Bids.objects.create(auction=auction, user = user, new_bid = new_bid)
> messages.success(request, 'Successfully added your bid')
> return HttpResponseRedirect(reverse("listing_detail", listing_id=listing_id))
> 
> ```

The three lines marked with `***` are unnecessary and can be removed.

The general flow is:

```auto
if form.is_valid():
    new_object = form.save(commit=False)
    new_object.field = "some updated value"
    new_object.save()

```

Also see [Creating forms from models | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/forms/modelforms/#the-save-method)

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 14, 2022, 5:47pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/33 "2022-03-14T17:47:17Z")

</div>

> [@KenWhitesell](#):
>
> (If necessary, review page 2 of the tutorial, including the section at [Playing with the API](https://docs.djangoproject.com/en/4.0/intro/tutorial02/#playing-with-the-api).

Reviewing this line in the page

```auto
# Access model field values via Python attributes.
>>> q.question_text
"What's new?"

```

I adjusted my code to

```auto
    def clean_new_bid(self):
        new_bid = self.cleaned_data['new_bid']
        starting_bid = self.auction.starting_bid 

```

> [@KenWhitesell](#):
>
> You then have a variable named `auction` (accessed as `self.auction` in that class) that accesses whatever value was passed into the form constructor.

Just want to explain my logic, using the first statement about accessing auction through ‘self.auction’ and this line ‘\>\>\> q.question\_text’ which accesses the field ‘question\_text’ through the variable ‘q’.

Unfortunately, still missing it because I get the Nonetype error still.

> [@KenWhitesell](#):
>
> The three lines marked with `***` are unnecessary and can be removed.
> 
> The general flow is:
> 
> ```auto
> if form.is_valid():
> new_object = form.save(commit=False)
> new_object.field = "some updated value"
> new_object.save()
> 
> ```

Thank you, this has been updated

```auto
        if bid_form.is_valid():
            accepted_bid = bid_form.save(commit=False)
            accepted_bid.new_bid = bid_form.cleaned_data['new_bid']
            accepted_bid.user = request.user 
            accepted_bid.save()

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 14, 2022, 6:32pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/34 "2022-03-14T18:32:48Z")

</div>

Ok, I’m missing something here regarding your `auction` object. I see no reason at the moment how/why you would be getting a `NoneType` error with it.

Can you post the complete error?

Regarding your new view:

> [@Theresa-o](#):
>
> ```auto
> if bid_form.is_valid():
> accepted_bid = bid_form.save(commit=False)
> *** accepted_bid.new_bid = bid_form.cleaned_data['new_bid']
> accepted_bid.user = request.user 
> accepted_bid.save()
> 
> ```

The marked line is unnecessary - that’s the data that is coming in from the form. You don’t need to do anything with it. The reason you have the `accepted_bid.user` line following it is because `user` is _not_ a field in the form.

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 14, 2022, 6:43pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/35 "2022-03-14T18:43:46Z")

</div>

# AttributeError at /make\_bid/2

‘NoneType’ object has no attribute ‘starting\_bid’

| Request Method: | POST |
| --- | --- |
| Request URL: | [http://127.0.0.1:8000/make\_bid/2](http://127.0.0.1:8000/make_bid/2) |
| Django Version: | 4.0.2 |
| Exception Type: | AttributeError |
| Exception Value: | ‘NoneType’ object has no attribute ‘starting\_bid’ |

## Traceback [Switch to copy-and-paste view](http://127.0.0.1:8000/make_bid/2#)

- `C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py` , line 47, in inner

…

Local vars

| | |
| --- | --- |
| | |
| | |
| | |

- `C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py` , line 181, in \_get\_response

…

Local vars

| | |
| --- | --- |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |

- `C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\decorators.py` , line 21, in \_wrapped\_view

…

Local vars

| | |
| --- | --- |
| | |
| | |
| | |
| | |
| | |
| | |
| | |

- `C:\Users\USER\Downloads\commerce\commerce\auctions\views.py` , line 146, in make\_bid

> [@KenWhitesell](#):
>
> The marked line is unnecessary - that’s the data that is coming in from the form. You don’t need to do anything with it. The reason you have the `accepted_bid.user` line following it is because `user` is _not_ a field in the form.

O, that makes sense. Thanks

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 14, 2022, 6:55pm UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/36 "2022-03-14T18:55:38Z")

</div>

It’s generally more helpful to get the error message from the console in which this is being run than what’s displayed on the web page, but we can try to work with this.

I’m guessing from context that line 146 from the referenced error message is the marked line here:

> [@Theresa-o](#):
>
> ```auto
> else:
> bid_form = BidForm(request.POST)
> context = {
> "bid_form": bid_form,
> "bid": bid,
> "bid_item": bid_item,
> "auction": auction
> } 
> 
> *** return render(request, 'auctions/details.html', context)
> 
> ```

The situation causing that issue is here:

> [@Theresa-o](#):
>
> ```auto
> else:
> *** bid_form = BidForm(request.POST)
> context = {
> "bid_form": bid_form,
> "bid": bid,
> "bid_item": bid_item,
> "auction": auction
> } 
> 
> ```

You should not be recreating the form again. You’re creating your instance of the form before the `is_valid` call, which makes it available on both sides of the condition. (The actual error is that, in recreating it here, you’re not passing the `auction` variable to the constructor. But you shouldn’t be recreating it at all.)

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 15, 2022, 10:53am UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/37 "2022-03-15T10:53:21Z")

</div>

I have one final problem bugging me, the bid price is not updating on the page when the user types it in

```auto
                            <hr>
                            <p>Current price: ${{ listing.bid }}</p>
                            <hr>

```

> [@KenWhitesell](#):
>
> It’s generally more helpful to get the error message from the console in which this is being run than what’s displayed on the web page, but we can try to work with this.

Ok

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 15, 2022, 11:01am UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/38 "2022-03-15T11:01:57Z")

</div>

Context please? I don’t see that in any of the previous templates you’ve posted nor a reference to it in the view you’ve been working on.

---

<div class="post-metadata">

**Author:** ![Theresa-o](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/theresa-o/32/7565_2.png) [@Theresa-o](https://forum.djangoproject.com/u/Theresa-o)\
**Post date:** [March 15, 2022, 11:07am UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/39 "2022-03-15T11:07:30Z")

</div>

The new bid amount that the user inputs should show on the homepage, so I’m trying to pass in the bid amount into my index.html file

INDEX.HTML

```auto
                  <h5>{{ listing.title|truncatewords:3 }}</h5>
                  <h6>${{ listing.bid }}</h6>
                  <small>{{ listing.description|truncatewords:6 }}</small>

```

> [@Theresa-o](#):
>
> ```auto
> def make_bid(request, listing_id):
> auction = Auction.objects.get(pk=listing_id)
> bid_item = Bids.objects.filter(auction=auction).order_by('-new_bid').first()
>     
> 
> #if theres no bid available, use starting bid, if available, update to the latest bid
> 
> if bid_item == None:
> bid = auction.starting_bid
> else:
> bid = bid_item.new_bid
> 
> ```

bid is gotten from this VIEW

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 15, 2022, 11:10am UTC](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382/40 "2022-03-15T11:10:37Z")

</div>

I need to see the view that is rendering the index.html template.

[Previous page](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382.md?page=1)

[Next page](https://forum.djangoproject.com/t/how-to-get-highest-bid-in-an-auction-bidding-site-django/12382.md?page=3)
