From 03c78f539d2fc0c346c467db132e231bfd2a4158 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 20 May 2021 17:16:25 +0200 Subject: [PATCH] fixed ordering --- cookbook/helper/recipe_search.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cookbook/helper/recipe_search.py b/cookbook/helper/recipe_search.py index 05c5828bf..45550be1b 100644 --- a/cookbook/helper/recipe_search.py +++ b/cookbook/helper/recipe_search.py @@ -30,6 +30,10 @@ def search_recipes(request, queryset, params): return queryset.filter(pk__in=list(set(last_viewed_recipes))[-search_last_viewed:]) + queryset = queryset.annotate( + new_recipe=Case(When(created_at__gte=(datetime.now() - timedelta(days=7)), then=Value(100)), + default=Value(0), )).order_by('-new_recipe', 'name') + if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2', 'django.db.backends.postgresql']: queryset = queryset.annotate(similarity=TrigramSimilarity('name', search_string), ).filter( @@ -63,10 +67,6 @@ def search_recipes(request, queryset, params): if search_internal == 'true': queryset = queryset.filter(internal=True) - queryset = queryset.annotate( - new_recipe=Case(When(created_at__gte=(datetime.now() - timedelta(days=7)), then=Value(100)), - default=Value(0), )).order_by('-new_recipe', 'name') - if search_random == 'true': queryset = queryset.order_by("?")