【发布时间】:2014-12-24 02:19:49
【问题描述】:
我正在尝试使用拍卖行风格模型的一些概念,现在我有一个Auction 模型和一个Bid 模型。两者通过 Bid 模型中的 ForeignKey 关联,Bid.amount 包含用户的出价金额。
我已经利用Bid.amount 字段上的排序来定义最高出价,但我想知道是否有一种简单的方法来定义max_bid 并且输出给用户的是看起来像“智能出价” " 系统,类似于 eBay。
所以说如果以下适用
$ bid1 = 9000 # max bid for bid1 object
$ bid2 = 6000 # max bid for bid2 object
$ bid3 = 9500 # max bid for bid3 object
$ starting_price = 5000 # starting price for the auction
当出价 1 被放置时(表明智能出价应达到的最高价为 9000),当前拍卖价格应保持在 5000,因为该项目没有其他出价。
当bid2被放置时,当前的拍卖价格应该增加到6001(因为bid1仍然更高)
当bid3被放置时,当前的拍卖价格应该增加到9001(超过bid1,并成为当前的最高出价者)。
如果有人对解决此问题的最佳方法有任何想法,我很想听听。
编辑:我的模型,供参考
class Auction(models.Model):
seller = models.ForeignKey(User)
item_id = models.CharField(max_length=255, blank=True, null=True)
item_name = models.CharField(max_length=255, blank=True, null=True)
winner = models.ForeignKey(User, related_name='Auction_Winner', blank=True, null=True)
reserve = models.CharField(max_length=255, blank=True, null=True)
is_guildbank_sale = models.BooleanField(default=True)
created = models.DateTimeField(editable=False, null=True)
expires = models.DateTimeField(editable=False, null=True)
def __unicode__(self):
return '%s selling %s' % (self.seller, self.item_name)
def save(self, *args, **kwargs):
''' On save, update timestamps '''
if not self.id:
self.created = datetime.today()
self.expires = datetime.today() + timedelta(days=3)
return super(Auction, self).save(*args, **kwargs)
class Bid(models.Model):
auction = models.ForeignKey(Auction, null=True)
user = models.ForeignKey(User, related_name='bid_owner', null=True)
bid_amount = models.IntegerField(blank=True, null=True)
class Meta:
verbose_name = "Auction Bid"
verbose_name_plural = "Auction Bids"
ordering = ['-bid_amount',]
get_latest_by = 'bid_amount'
【问题讨论】:
标签: python django django-models