def get(self, request, format=None): trending = Food.objects.order_by("-updated_at")[:12].all() trending = prepare_food(request, trending) trending = FoodSerializer(trending, many=True).data # trending = self.prepare_data(request=request, data=trending) hot_stuff = Food.objects.order_by("-numRating")[:12].all() hot_stuff = prepare_food(request, hot_stuff) hot_stuff = FoodSerializer(hot_stuff, many=True).data popular = Food.objects.order_by("-avgRating")[:12].all() popular = prepare_food(request, popular) popular = FoodSerializer(popular, many=True).data return Response({"trending": trending, "hot stuff": hot_stuff, "popular": popular})
def get(self, request, search_term, format=None): if request.query_params.get('results_per_page') is not None: results_per_page = int( request.query_params.get('results_per_page')) else: results_per_page = 12 if request.query_params.get('page_number') is not None: page_number = int(request.query_params.get('page_number')) else: page_number = 1 terms = search_term.split(' ') q_objects = Q() for term in terms: tags = Tag.objects.filter(name__icontains=term) q_objects &= Q(name__icontains=term) | Q(tags__in=tags) foods = Food.objects.filter(q_objects).all().distinct() total_pages = len(foods) // results_per_page if not foods: data = [] else: foods = prepare_food( request, foods[(page_number - 1) * 12:(page_number) * 12]) data = FoodSerializer(foods, many=True).data return Response({ 'data': data, 'pagination': { 'results_per_page': results_per_page, 'page_number': page_number, 'total_pages': total_pages } })
def get(self, request, format=None): trending = Food.objects.order_by('-updated_at')[:12].all() trending = prepare_food(request, trending) trending = FoodSerializer(trending, many=True).data # trending = self.prepare_data(request=request, data=trending) hot_stuff = Food.objects.order_by('-numRating')[:12].all() hot_stuff = prepare_food(request, hot_stuff) hot_stuff = FoodSerializer(hot_stuff, many=True).data popular = Food.objects.order_by('-avgRating')[:12].all() popular = prepare_food(request, popular) popular = FoodSerializer(popular, many=True).data return Response({ 'trending': trending, 'hot stuff': hot_stuff, 'popular': popular })
def get(self, request, search_term, format=None): if request.query_params.get('results_per_page') is not None: results_per_page = int(request.query_params.get('results_per_page')) else: results_per_page = 12 if request.query_params.get('page_number') is not None: page_number = int(request.query_params.get('page_number')) else: page_number = 1 terms = search_term.split(' ') q_objects = Q() for term in terms: tags = Tag.objects.filter(name__icontains=term) q_objects &= Q(name__icontains=term) | Q(tags__in=tags) foods = Food.objects.filter(q_objects).all().distinct() total_pages = len(foods) // results_per_page if not foods: data = [] else: foods = prepare_food(request, foods[(page_number - 1) * 12:(page_number) * 12]) data = FoodSerializer(foods, many=True).data return Response({'data': data, 'pagination': {'results_per_page': results_per_page, 'page_number': page_number, 'total_pages': total_pages}})
def prepare_data(request, data): data = prepare_food(request, data) data = FoodSerializer(data, many=True).data return data
def get(self, request, account_pk, format=None): favorites = self.get_object(account_pk=account_pk) favorites = prepare_food(request, favorites) serializer = FoodSerializer(favorites, many=True) return Response(serializer.data)
def get(self, request, restaurant_pk, format=None): foods = self.get_object(restaurant_pk=restaurant_pk) foods = prepare_food(request, foods) serializer = FoodSerializer(foods, many=True) return Response(serializer.data)
def get(self, request, pk, format=None): food = self.get_object(pk) food = prepare_food(request, [food])[0] serializer = FoodSerializer(food) return Response(serializer.data)
def get(self, request, format=None): foods = Food.objects.all() foods = prepare_food(request, foods) serializer = FoodSerializer(foods, many=True) return Response(serializer.data)