Skip to content

Commit

Permalink
reverse trending list, implement backup variant if the results are le…
Browse files Browse the repository at this point in the history
…ss than 15
  • Loading branch information
mikebgrep committed Oct 12, 2024
1 parent a71ebc8 commit 8e1f2bf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions foodie_be/foodie/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import mimetypes
import os

from django.http import HttpResponseBadRequest, HttpResponse, Http404
from django.shortcuts import get_list_or_404, get_object_or_404
from rest_framework import filters
from rest_framework.decorators import action
Expand All @@ -14,7 +10,6 @@
from .HeaderAuthentication import HeaderAuthentication
from .models import Category, Recipe, Tag
from .serializers import RecipesSerializer, CategorySerializer, TagsSerializer
from foodie_be import settings


class SearchRecipies(ListAPIView):
Expand Down Expand Up @@ -49,7 +44,11 @@ class TrendingRecipies(ListAPIView):

def get_queryset(self):
results_pks = [x.pk for x in Recipe.objects.all() if x.is_trending == True][:15]
return Recipe.objects.filter(pk__in=results_pks)
if len(results_pks) < 15:
for pk in [x.pk for x in Recipe.objects.order_by('-pk')[:15 - len(results_pks)]]:
results_pks.append(pk)

return Recipe.objects.filter(pk__in=results_pks).order_by('-pk')


class FavoriteRecipes(ModelViewSet):
Expand Down

0 comments on commit 8e1f2bf

Please sign in to comment.