modify article API return

This commit is contained in:
Ludovic Stephan 2017-03-09 09:21:07 -03:00
parent c9b7683238
commit 8aa4fa2dce

View file

@ -1338,13 +1338,27 @@ def history_json(request):
opegroups_list.append(opegroup_dict)
return JsonResponse({ 'opegroups': opegroups_list })
@teamkfet_required
def kpsul_articles_data(request):
articles = (
Article.objects
.values('id', 'name', 'price', 'stock', 'category_id', 'category__name')
.filter(is_sold=True))
return JsonResponse({ 'articles': list(articles) })
.filter(is_sold=True)
.select_related('category'))
articlelist = []
for article in articles:
articlelist.append({
'id': article.id,
'name': article.name,
'price': article.price,
'stock': article.stock,
'category': {
'id': article.category.id,
'name': article.category.name,
}
})
return JsonResponse(articlelist, safe=False)
@teamkfet_required
def history(request):