Selling can be sorted by any ItemListing field
parent
52f5bf33bb
commit
8a47017ae1
|
@ -232,9 +232,9 @@ def selling(item_name, sort="normalized_price"):
|
||||||
'''
|
'''
|
||||||
:request: GET
|
:request: GET
|
||||||
:param item_name: Item name to search for
|
:param item_name: Item name to search for
|
||||||
:param sort: Field to sort shop results by
|
:param sort: Field to sort shop results by, default is price
|
||||||
:return: List of top matches shop, sorted by when they were added
|
:return: List of top matching shops, sorted by the
|
||||||
:help: List shops selling an item. Sorted by most recently added
|
:help: Lists shops selling an item.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
@ -254,7 +254,7 @@ def selling(item_name, sort="normalized_price"):
|
||||||
|
|
||||||
item_query = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \
|
item_query = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \
|
||||||
.filter(item_name__icontains=item_name, shop_id=shop_id['shop_id']) \
|
.filter(item_name__icontains=item_name, shop_id=shop_id['shop_id']) \
|
||||||
.order_by('normalized_price') \
|
.order_by(sort) \
|
||||||
.values("item_name", "price", "amount")
|
.values("item_name", "price", "amount")
|
||||||
|
|
||||||
item_list = []
|
item_list = []
|
||||||
|
|
|
@ -78,7 +78,7 @@ class ItemListing(models.Model):
|
||||||
item_name = models.CharField(max_length=128)
|
item_name = models.CharField(max_length=128)
|
||||||
price = models.IntegerField()
|
price = models.IntegerField()
|
||||||
amount = models.IntegerField()
|
amount = models.IntegerField()
|
||||||
|
date_restocked = models.DateTimeField(auto_now=True)
|
||||||
shop = models.ForeignKey(Shop, related_name="shop_selling", on_delete=models.CASCADE)
|
shop = models.ForeignKey(Shop, related_name="shop_selling", on_delete=models.CASCADE)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in New Issue