Issue
I have model class Bid
in my auction app that stores bids placed on items:
class Bid(models.Model):
title = models.CharField(max_length=64, blank=True)
date_time = models.DateTimeField(default=timezone.now, blank=True)
price = models.DecimalField(max_digits=4, decimal_places=2)
user = models.CharField(max_length=64)
I want to query all bid prices placed on a particular item:
bids = Bid.objects.all().filter(title=title)
Returns all items with that title, but I just want the price
column. I tried :
bids = bids.price
But it didn't work.
Solution
If you need only the prices based on the title of bid :
bids = Bid.objects.all().filter(title=title).values_list("price", flat = True)
Answered By - Naser Fazal khan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.