Official field in CategoryTag and categories in initial endpoint
This commit is contained in:
@@ -120,6 +120,24 @@ def get_latest_companies(number):
|
||||
result = CompanySerializer(companies_qs, many=True).data
|
||||
return result
|
||||
|
||||
def get_popular_categories(number):
|
||||
categories_list = list(CategoryTag.objects.filter(level=1, official=True).values_list('name', flat=True))
|
||||
counted_categories = []
|
||||
for cat in categories_list:
|
||||
count = 0
|
||||
categories = get_category_and_descendants(cat)
|
||||
for i in categories:
|
||||
count += i.count
|
||||
counted_categories.append({
|
||||
"name": cat,
|
||||
"image": None,
|
||||
"count": count
|
||||
})
|
||||
popular = sorted(counted_categories, key=lambda d: d['count'], reverse=True)[:number]
|
||||
return popular
|
||||
|
||||
|
||||
|
||||
|
||||
@api_view(['GET',]) # include allowed methods
|
||||
def initial(request):
|
||||
@@ -135,8 +153,14 @@ def initial(request):
|
||||
|
||||
products = get_latest_products(12)
|
||||
companies = get_latest_companies(12)
|
||||
categories = get_popular_categories(12)
|
||||
|
||||
return Response(data={"cards": category_cards, "products": products, "companies": companies})
|
||||
return Response(data={
|
||||
"cards": category_cards,
|
||||
"products": products,
|
||||
"companies": companies,
|
||||
"categories": categories
|
||||
})
|
||||
|
||||
|
||||
@api_view(['POST',])
|
||||
|
||||
Reference in New Issue
Block a user