Selling command now fully replimented.
parent
00fe2d72ab
commit
52f5bf33bb
|
@ -227,12 +227,12 @@ def add_item(item_name, quantity, diamond_price, shop_name=None, discord_uuid=No
|
|||
return item_listing.json
|
||||
|
||||
|
||||
# TODO Re-implement selling shop search
|
||||
@command("GET")
|
||||
def selling(item_name):
|
||||
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
|
||||
'''
|
||||
|
@ -242,11 +242,13 @@ def selling(item_name):
|
|||
raise EmptryString
|
||||
|
||||
shops = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \
|
||||
.filter(item_name__icontains=item_name).order_by('normalized_price').values('shop_id').distinct()
|
||||
.filter(item_name__icontains=item_name).order_by(sort).values('shop_id').all()
|
||||
|
||||
if len(shops) == 0:
|
||||
raise ItemNotFound
|
||||
|
||||
shops = [i for n, i in enumerate(shops) if i not in shops[n + 1:]]
|
||||
|
||||
for shop_id in shops:
|
||||
shop = Shop.objects.get(pk=shop_id['shop_id']).json
|
||||
|
||||
|
|
Loading…
Reference in New Issue