Fixed some Shit

master
Michael Vignotto 2020-06-03 21:35:10 +02:00
parent 5c449851ac
commit 7fc3f8e14d
3 changed files with 3 additions and 6 deletions

View File

@ -12,9 +12,9 @@
<div class="card mt-3"> <div class="card mt-3">
<div class="card-header"> <div class="card-header">
<h1 class="text-center text-muted">In totale nel nostro Salone Bar abbiamo trovato {{ cocktail.count }} cocktails {% if cocktail.count == 1 %} che corrisponde {% else %} che corrispondono {% endif %} alla tua ricerca <i class="fas fa-cocktail"></i> </h1> <h1 class="text-center text-muted">In totale nel nostro Salone Bar abbiamo trovato {{ cocktail.count }} cocktails {% if cocktail.count == 1 %} che corrisponde {% else %} che corrispondono {% endif %} alla tua ricerca <i class="fas fa-cocktail"></i> </h1>
</div>
</div>
{% for cocktails in cocktail %} {% for cocktails in cocktail %}
</div>
</div>
<!-- {{ cocktail.ingredienti.all }} <!-- {{ cocktail.ingredienti.all }}
{{ cocktail.nome_cocktail }} --> {{ cocktail.nome_cocktail }} -->
{% if forloop.first %} <div class="row"> {% endif %} {% if forloop.first %} <div class="row"> {% endif %}

View File

@ -1,7 +1,6 @@
from django.shortcuts import render,get_object_or_404,redirect from django.shortcuts import render,get_object_or_404,redirect
from .models import Cocktail,Ingredienti,Strumenti,Bicchieri from .models import Cocktail,Ingredienti,Strumenti,Bicchieri
import random import random
import time
# Create your views here. # Create your views here.
@ -63,14 +62,12 @@ def bicchieri_cocktail(request):
def cerca(request): def cerca(request):
if "q" in request.GET: if "q" in request.GET:
querystring = request.GET.get("q") querystring = request.GET.get("q")
if len(querystring) == 0: if len(querystring) < 3:
return redirect("cerca") return redirect("cerca")
all_ingredients = Cocktail.objects.all() all_ingredients = Cocktail.objects.all()
searching_ingred = Cocktail.objects.none() searching_ingred = Cocktail.objects.none()
for one_ingredient in querystring.split(","): for one_ingredient in querystring.split(","):
print(one_ingredient)
searching_ingred = searching_ingred.union(searching_ingred, all_ingredients.filter(ingredienti__ingrediente__icontains=one_ingredient)) searching_ingred = searching_ingred.union(searching_ingred, all_ingredients.filter(ingredienti__ingrediente__icontains=one_ingredient))
print(searching_ingred)
# ingrediente = Cocktail.objects.filter(ingredienti__ingrediente__icontains=querystring).order_by("-nome_cocktail") # ingrediente = Cocktail.objects.filter(ingredienti__ingrediente__icontains=querystring).order_by("-nome_cocktail")
cocktail = Cocktail.objects.filter(nome_cocktail__icontains=querystring).order_by("-nome_cocktail") cocktail = Cocktail.objects.filter(nome_cocktail__icontains=querystring).order_by("-nome_cocktail")
context = {"querystring":querystring,"cocktail":cocktail,"ingrediente":searching_ingred} context = {"querystring":querystring,"cocktail":cocktail,"ingrediente":searching_ingred}