From e94e15cfcb46b1607fc639eba90f16315dfa0b90 Mon Sep 17 00:00:00 2001 From: Bruno Cesar Date: Sun, 8 Nov 2020 20:09:57 -0300 Subject: [PATCH] Adiciona busca por receitas --- apps/receitas/templates/index.html | 1 + apps/receitas/templates/partials/header.html | 4 ++-- apps/receitas/views.py | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/receitas/templates/index.html b/apps/receitas/templates/index.html index 6289ee6..e0632a5 100755 --- a/apps/receitas/templates/index.html +++ b/apps/receitas/templates/index.html @@ -32,6 +32,7 @@
{{ receita }}
{% endfor %} {% else %} +

Não foram encontradas receitas.

{% endif %} diff --git a/apps/receitas/templates/partials/header.html b/apps/receitas/templates/partials/header.html index b911ae6..35db9f7 100644 --- a/apps/receitas/templates/partials/header.html +++ b/apps/receitas/templates/partials/header.html @@ -7,8 +7,8 @@
-
- + +
diff --git a/apps/receitas/views.py b/apps/receitas/views.py index 58240c7..5b705d3 100644 --- a/apps/receitas/views.py +++ b/apps/receitas/views.py @@ -3,7 +3,12 @@ def index(request): - receitas = Receita.objects.filter(publicada=True).order_by('-data_criacao') + receitas = Receita.objects.filter(publicada=True) + + if 'procurar_receita' in request.GET and request.GET['procurar_receita']: + receitas = receitas.filter(nome__icontains=request.GET['procurar_receita']) + + receitas = receitas.order_by('-data_criacao') return render(request, 'index.html', {'receitas': receitas})