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