meal plan random fix
This commit is contained in:
@ -17,6 +17,7 @@ def search_recipes(queryset, params):
|
|||||||
search_books_or = params.get('books_or', True)
|
search_books_or = params.get('books_or', True)
|
||||||
|
|
||||||
search_internal = params.get('internal', None)
|
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']:
|
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')
|
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':
|
if search_internal == 'true':
|
||||||
queryset = queryset.filter(internal=True)
|
queryset = queryset.filter(internal=True)
|
||||||
|
|
||||||
|
if search_random == 'true':
|
||||||
|
queryset = queryset.order_by("?")
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
@ -513,7 +513,7 @@
|
|||||||
if (this.recipe_query !== '') {
|
if (this.recipe_query !== '') {
|
||||||
url += '&query=' + this.recipe_query;
|
url += '&query=' + this.recipe_query;
|
||||||
} else {
|
} else {
|
||||||
url += '&random=True'
|
url += '&random=true'
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$http.get(url).then((response) => {
|
this.$http.get(url).then((response) => {
|
||||||
|
@ -328,6 +328,11 @@ class RecipeSchema(AutoSchema):
|
|||||||
"description": 'true or false. If only internal recipes should be returned or not.',
|
"description": 'true or false. If only internal recipes should be returned or not.',
|
||||||
'schema': {'type': 'string', },
|
'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
|
return parameters
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user