diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index e0f604ef8..821184f53 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -17,6 +17,7 @@ def search_recipes(queryset, params): search_books_or = params.get('books_or', True) search_internal = params.get('internal', None) + search_random = params.get('random', False) if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2', 'django.db.backends.postgresql']: queryset = queryset.annotate(similarity=TrigramSimilarity('name', search_string), ).filter(Q(similarity__gt=0.1) | Q(name__unaccent__icontains=search_string)).order_by('-similarity') @@ -49,4 +50,7 @@ def search_recipes(queryset, params): if search_internal == 'true': queryset = queryset.filter(internal=True) + if search_random == 'true': + queryset = queryset.order_by("?") + return queryset diff --git a/cookbook/templates/meal_plan.html b/cookbook/templates/meal_plan.html index d7b43dec7..38e5c26df 100644 --- a/cookbook/templates/meal_plan.html +++ b/cookbook/templates/meal_plan.html @@ -513,7 +513,7 @@ if (this.recipe_query !== '') { url += '&query=' + this.recipe_query; } else { - url += '&random=True' + url += '&random=true' } this.$http.get(url).then((response) => { diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 4a7b7ed68..bf934d68a 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -328,6 +328,11 @@ class RecipeSchema(AutoSchema): "description": 'true or false. If only internal recipes should be returned or not.', 'schema': {'type': 'string', }, }) + parameters.append({ + "name": 'random', "in": "query", "required": False, + "description": 'true or false. returns the results in randomized order.', + 'schema': {'type': 'string', }, + }) return parameters