Skip to content

Commit

Permalink
Adiciona busca por receitas
Browse files Browse the repository at this point in the history
  • Loading branch information
brnocesar committed Nov 8, 2020
1 parent 348567b commit e94e15c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/receitas/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h5>{{ receita }}</h5>
</div>
{% endfor %}
{% else %}
<p>Não foram encontradas receitas.</p>
{% endif %}

</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/receitas/templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<div class="container">
<div class="row">
<div class="col-12">
<form action="#" method="post">
<input type="search" name="search" placeholder="O que está procurando...">
<form action="{% url 'index' %}" method="GET">
<input type="search" name="procurar_receita" placeholder="Uma receita especial...">
<button type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
</div>
Expand Down
7 changes: 6 additions & 1 deletion apps/receitas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down

0 comments on commit e94e15c

Please sign in to comment.