我有3个models.item,auction_items,auction_bids。 项目表包含一般信息。 auction_items表包含拍卖详情,如start_time,end_time,start_price,如果该项目是auction_item。 auction_bids表处理每个auction_item的出价。
models.py
class item(models.Model):
title = models.CharField(max_length=200,null=False,blank=False)
description = models.CharField(max_length=200,null=True,blank=True)
ad_type = models.SmallIntegerField(max_length=2,default=1,null=False,blank=True)
class auction_item(models.Model):
advt = models.ForeignKey(item)
start_time = models.DateTimeField(null=False,blank=True)
end_time = models.DateTimeField(null=False,blank=True)
start_price = models.DecimalField(null=False,max_digits=7,decimal_places=2,blank=True)
class auction_bids(models.Model):
advt_auction = models.ForeignKey(auction_item)
bidder_id = models.CharField(max_length=200,null=False,blank=True)
price = models.DecimalField(null=False,decimal_places=2,max_digits=7,blank=True)
search_indexs.py
class AuctionIndexes(indexes.SearchIndex,indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
ad_id=indexes.IntegerField(null=False)
title = indexes.CharField()
description = indexes.CharField(null=True)
start_time= indexes.DateTimeField(model_attr='start_time',faceted=True)
end_time= indexes.DateTimeField(model_attr='end_time',faceted=True)
start_price= indexes.IntegerField(model_attr='start_price')
current_bid=indexes.IntegerField(null=True)
def get_model(self):
return auction_items
def prepare_ad_id(self,obj):
return obj.item.pk
def prepare_title(self, obj):
return obj.item.title
def prepare_description(self, obj):
return obj.item.description
def prepare_current_bid(self, obj):
try:
return int(auction_bids.objects.filter(advt_auction=obj.pk).values('auction_item_id').annotate(current_bid = Max('price'))[0]['current_bid'])
except:
return None
class AuctionBidsIndexes(indexes.SearchIndex,indexes.Indexable):
text=indexes.CharField(document=True, use_template=False)
auction_item = indexes.IntegerField(model_attr='auction_item_id')
bidder_face_id = indexes.CharField(model_attr='bidder_id')
bid_price = indexes.IntegerField(model_attr='price')
def get_model(self):
return advt_auction_bids
如果某人对该项目出价,如何更新current_bid
。
我使用solr作为搜索引擎。
请给我任何建议。