diff --git a/cookbook/models.py b/cookbook/models.py
index 2f1309e10..875836bed 100644
--- a/cookbook/models.py
+++ b/cookbook/models.py
@@ -7,6 +7,7 @@ from django.contrib import auth
from django.contrib.auth.models import User, Group
from django.utils.translation import gettext as _
from django.db import models
+from django_random_queryset import RandomManager
from recipes.settings import COMMENT_PREF_DEFAULT
@@ -198,6 +199,8 @@ class Recipe(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
+ objects = RandomManager()
+
def __str__(self):
return self.name
diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html
index 22ae397f7..7d9839977 100644
--- a/cookbook/templates/meal_plan.html
+++ b/cookbook/templates/meal_plan.html
@@ -103,8 +103,15 @@
{
diff --git a/cookbook/views/api.py b/cookbook/views/api.py
index 86ad5ebd7..94c06c5d6 100644
--- a/cookbook/views/api.py
+++ b/cookbook/views/api.py
@@ -205,9 +205,15 @@ 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()
internal = self.request.query_params.get('internal', None)
if internal:
- self.queryset = self.queryset.filter(internal=True)
+ 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()
diff --git a/requirements.txt b/requirements.txt
index 5495da733..0349aa839 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -25,4 +25,5 @@ icalendar==4.0.6
pyyaml==5.3.1
uritemplate==3.0.1
beautifulsoup4==4.9.2
-microdata==0.7.1
\ No newline at end of file
+microdata==0.7.1
+django-random-queryset==0.1.3
\ No newline at end of file