28 lines
913 B
Python
28 lines
913 B
Python
from django.shortcuts import render,get_object_or_404,redirect
|
|
from .models import Cocktail,Ingredienti
|
|
|
|
# Create your views here.
|
|
|
|
|
|
def homepage(request):
|
|
lista_cocktail = Cocktail.objects.all()
|
|
context = {"lista_cocktail":lista_cocktail}
|
|
return render(request,"homepage.html",context)
|
|
|
|
|
|
def cocktail(request,nome_cocktail):
|
|
cocktail = get_object_or_404(Cocktail,nome_cocktail=nome_cocktail)
|
|
context = {"cocktail":cocktail}
|
|
return render(request,"cocktail.html",context)
|
|
|
|
def cerca(request):
|
|
if "q" in request.GET:
|
|
querystring = request.GET.get("q")
|
|
if len(querystring) == 0:
|
|
return redirect("cerca/")
|
|
cocktail = Cocktail.objects.filter(nome_cocktail__icontains=querystring).order_by("-nome_cocktail")
|
|
context = {"cocktail":cocktail}
|
|
return render(request,"cerca.html",context)
|
|
else:
|
|
return render(request,"cerca.html")
|