Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @require_GET
- def show(request):
- load = LoadOrder.objects.last()
- if not load:
- return HttpResponse('Выгрузок еще не было!')
- transactions = Transaction.objects.filter(load=load)
- result = []
- for transaction in transactions:
- obj = {
- 'username': transaction.customer,
- 'spent_money': transaction.total,
- 'gems': [transaction.item]
- }
- customer_exist = False
- for item in result:
- if item['username'] == obj['username']:
- item['spent_money'] = item['spent_money'] + obj['spent_money']
- if obj['gems'][0] not in item['gems']:
- item['gems'].append(obj['gems'][0])
- customer_exist = True
- break
- if not customer_exist:
- result.append(obj)
- result = sorted(result, key=lambda i: item['spent_money'], reverse=True)[:5]
- for item in result:
- sorted_gems = []
- for gem in item['gems']:
- for other in result:
- if other != item:
- if gem in other['gems']:
- sorted_gems.append(gem)
- break
- item['gems'] = sorted_gems
- response = json.dumps(
- result,
- ensure_ascii=False,
- indent=4
- )
- return JsonResponse(response, safe=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement