diff --git a/api/commands.py b/api/commands.py index c349530..6cbd219 100644 --- a/api/commands.py +++ b/api/commands.py @@ -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 = [] diff --git a/models.py b/models.py index 03cfd10..0b8b7a6 100644 --- a/models.py +++ b/models.py @@ -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