Skip to content

Commit

Permalink
improved random recipe queryset function
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Nov 4, 2020
1 parent 8d58254 commit 591d185
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,16 @@ class RecipeViewSet(viewsets.ModelViewSet, StandardFilterMixin):
permission_classes = [CustomIsShare | CustomIsGuest] # TODO split read and write permission for meal plan guest

def get_queryset(self):
queryset = Recipe.objects.all()
queryset = self.queryset

internal = self.request.query_params.get('internal', None)
if internal:
queryset = queryset.filter(internal=True)
random = self.request.query_params.get('random', False)
if random:
queryset = queryset.random(5)

self.queryset = queryset

return super(RecipeViewSet, self).get_queryset()
return queryset

# TODO write extensive tests for permissions

Expand Down

0 comments on commit 591d185

Please sign in to comment.