Skip to content

Commit

Permalink
Implementa exclusão de receita
Browse files Browse the repository at this point in the history
  • Loading branch information
brnocesar committed Jan 25, 2021
1 parent 60490f1 commit 67eb563
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/receitas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

urlpatterns = [
path('', views.index, name='index'),
path('receitas/<int:receita_id>', views.receita, name='receita'),
path('receitas/<int:receita_id>', views.receita, name='receita'), # mudar o nome dessa rota para receita.show
path('receitas/criar', views.create, name='receita.create'),
path('receitas/deletar/<int:receita_id>', views.destroy, name='receita.destroy'),
]
8 changes: 8 additions & 0 deletions apps/receitas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ def create(request):
return redirect('dashboard')

return render(request, 'receitas/create.html')

def destroy(request, receita_id):
# abstrair isso para um metodo que da um retorno mais adequado no caso de nao existir
# ou usar algo que de pra verificar se nao existe
receita = get_object_or_404(Receita, pk=receita_id)
receita.delete()

return redirect('dashboard')
1 change: 1 addition & 0 deletions apps/templates/usuarios/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h3>Olá {{ user.username }}</h3>
<a href="{% url 'receita' receita.id %}">
<h5>{{ receita }}</h5>
</a>
<a href="{% url 'receita.destroy' receita.id %}" type="button" class="btn btn-danger">Deletar</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 67eb563

Please sign in to comment.