From 9d73d299dafad6594bbe5c465bd39a518ba8c587 Mon Sep 17 00:00:00 2001 From: Michael Vignotto Date: Wed, 27 May 2020 21:39:14 +0200 Subject: [PATCH] =?UTF-8?q?Aggiunta=20Funzionalit=C3=A1=20Random=20per=20C?= =?UTF-8?q?ocktail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocktail/__pycache__/settings.cpython-37.pyc | Bin 2426 -> 2478 bytes cocktail/settings.py | 4 +- cocktail/templates/base.html | 14 ++++ .../__pycache__/models.cpython-37.pyc | Bin 2263 -> 2296 bytes cocktail_list/__pycache__/urls.cpython-37.pyc | Bin 351 -> 457 bytes .../__pycache__/views.cpython-37.pyc | Bin 1065 -> 1510 bytes .../migrations/0003_auto_20200526_1705.py | 18 +++++ .../migrations/0004_auto_20200527_1858.py | 18 +++++ .../0003_auto_20200526_1705.cpython-37.pyc | Bin 0 -> 1147 bytes .../0004_auto_20200527_1858.cpython-37.pyc | Bin 0 -> 1144 bytes cocktail_list/models.py | 16 ++--- cocktail_list/templates/cerca.html | 40 +++++++++++ cocktail_list/templates/cocktail.html | 3 +- cocktail_list/templates/homepage.html | 32 +++------ cocktail_list/templates/random_cocktail.html | 31 ++++++++ cocktail_list/urls.py | 5 +- cocktail_list/views.py | 13 +++- db.sqlite3 | Bin 163840 -> 163840 bytes static-storage/css/navbar_style.css | 67 ++++++++++++++++++ static-storage/css/style.css | 22 ++++++ 20 files changed, 247 insertions(+), 36 deletions(-) create mode 100644 cocktail_list/migrations/0003_auto_20200526_1705.py create mode 100644 cocktail_list/migrations/0004_auto_20200527_1858.py create mode 100644 cocktail_list/migrations/__pycache__/0003_auto_20200526_1705.cpython-37.pyc create mode 100644 cocktail_list/migrations/__pycache__/0004_auto_20200527_1858.cpython-37.pyc create mode 100644 cocktail_list/templates/cerca.html create mode 100644 cocktail_list/templates/random_cocktail.html create mode 100644 static-storage/css/navbar_style.css create mode 100644 static-storage/css/style.css diff --git a/cocktail/__pycache__/settings.cpython-37.pyc b/cocktail/__pycache__/settings.cpython-37.pyc index ccbf89115ee7139a1dab503a86446054c428cbd3..835cc4a4c317b47fd89e26cf0040dac4255f3fc1 100644 GIT binary patch delta 121 zcmew*v`(1MiI(#U=SgiRr1D(wk?pt1(L75(o})4Dob!^Yn2Ij(7143SP-j XqyjX&NM-T~ju6I}$+DcWOe{iI + {% block css %} {% endblock css %} {% block title %} {% endblock title %} +
+ Home + Strumenti + Bicchieri + Random Cocktail +
+
+ + +
+
+
{% block content %} @@ -24,5 +37,6 @@ + \ No newline at end of file diff --git a/cocktail_list/__pycache__/models.cpython-37.pyc b/cocktail_list/__pycache__/models.cpython-37.pyc index 2e8e74c6c2618af028685ad0200bfbc8c971999b..030f0cdb5aad07b3d185778301100de7582dd8f4 100644 GIT binary patch delta 274 zcmcaE_(PD_iIOUrpXk=9$ZjVT2+-_#c8Mj zWlp}&w24uD@+9W#j9QbkSehB_Cck5`oUF?FjFSWCp&EuPhS`&a*o+v>CcCoDV6>ck Vk8LHR&EyXDGmLtZLpd55H30k!O@IIZ delta 238 zcmew%cwLa!iIr?Jgow4VH*Z6%}KXmXle0?_GjndSCZ`r9C*I;OO3X{i&y5F)Pwci-uVMoW z>ld*Bbyf)=B*B{Wi`ap}ewrK;k1H#Hm4F3qahDe50PQPDEy^oi$xy@#R8+(}i7}K9 OLt4gsWshr-fN01SvBLh9xLEA<(0>Nxc5NKo185X6Q= z@XC;kj39v+Sy}i1{s63uth|?~A@_9e|9d~*&!6nyPUpVowHcl-KYl&^Y0NrT;mPdw zodc$1Y6X@ul=+4Qwz8CswxwFCjkc{E<)U?zJYv2#OCLl3^S7^XZsI11_W|Dg5vqa> zVa^wOtKv_KW(lw2*FhHuE&@4fj?_iEUX#tfek-d^D>!YaTk~zDS z#N5iC@*}1g^4RJ(aH-7QOtKSRj<}QXgaY^rWQEcd(*6KlLS9^c9+%>vX1!p=ZkoB$+J7;6}^7_!-lf+pW#HgQW~t6|DytYt3Ys9{K9 zuVHRx4rYL`o0)aAi+PAy7K)YoK;lE}-?O^r{^PtGn$%*>fw z$s)~KBnVV8`67#pFiR0PkQv2YSejZ?SzJ<-nU_AWI#T1xsG=$d3RFP*p@2r!iS}I^X`r7d?dlb-RoWHah*_BV1xu5h*Wwgtlm{h} zV-uZiocTE#s*F@nMio#)b)->!QZ19y+Qa}Is!#(1>R>_xR$vvHa0l+f8r*~X@Bkjd zBX|r?;3+(V=dcbh;3aH?>#zwecy+14>q`xD*5M5n_m-PSvMMaG8Kl8Q;j@TDEH6fz zmSs8QT4QnShb*Dj3SVJKm{DLfDcH=!vcJrHbc^3VF`4Ea9nN*H6-OB8wuMpEwq#hs zsx7G_s3WN(s3WN>s4J-}s4Hn#(5|FiLA#QAf_jpAf_jqn1no)M6SOC3U(mj!eL?$@ z4g?)YIuLXq=}^$2q(ec6ON!@E;u?M}&cm<|(jZ{|yl%Hb;o+IpoKmFoy0g$|skuwd zy`^=RTKAUbEj8~(Gxla@v?$ozbX!XoGa4t;Y&M^#bJK1u-ORwB@@fN3TjNGBPFX;6 zZU8;^XHkKT?0+Q@O~PV~ydhedBz{b}E^PIj(Fl&)Ca)8r6T%yW;JR5v(O)G5`y?vY zmJ!e?O@Jl=qj^@rm-5C=RM6~WnI*$3sBm*{>@Q;8NT+mpi+(AYg;bb-q;s0nEbqiD z82dEp?9=?BNT;3siJyci+1)w$)RCQh?T9wVN94WiV8gq_pA{)_EXT4ur$_9*ox5^ D>6bmo literal 0 HcmV?d00001 diff --git a/cocktail_list/migrations/__pycache__/0004_auto_20200527_1858.cpython-37.pyc b/cocktail_list/migrations/__pycache__/0004_auto_20200527_1858.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..775b0c0d44ea4ba19fae0429e13199b51b9beb1b GIT binary patch literal 1144 zcmY+EOK;Oa5Xb#WVy6w1XMsW+9zu!)jURCy5<-1Jg+zO)xa7df^=uQTjvf4vz*o5T zLvZ99aOchyX|J666*w{8WJ_6V$20%mdOf?I^-iNvm$1G1{`37WRg!*}foK{!TiDa5 zXg~rvl&11fo+?8{mi8r3K>Z?tO67_ASskjN9Z9XqIgXWD3ad|pQQ~Dm9Hp!}je&-# zUn0>q(AmPCo}i)9PzGtJfIO0iD%B>Ha&lUo)Ifs@RG|hs7*K~LScV2%fvd0r*Wfzb zfSYg&Zo?|vfxB=I*5E!ofc4QDY(Ntpo~iKYOvO2Mc#O$CVa9>T3R7(Ov45I*K}fuEGD*To2F}biPbY*wiHC8ghD{0EXWN^_e1WXoBjBTlc?^&+d^}j(+~sA zGBK)HrU*+|u>`d_wFR{~wFPxJbp&-dbp-8j+7YzFX-80(Q&&)zQ&-R~r(Hq2oOT86 zaoQ8K$7xT{KBs*_`<(U#9dJ4jbinCgL2(~ST*VvTk3zSa`?2o_Ug?dv*HVg_%~e|H z_FSZ;=m^odBzA<@xg@$mbT33!+s%(@mIa03G#4&@p4!nY$%`T`46C_t6CJPP{?;{CmG|I-v>%5Lh zr2Q_XN!p$U{@9~odyl54Sv+g+O}uCnlb!9OH*Hbc7Y?s+d_)||HdcG*ziRIhtMB$V zXP=Vt;8(Gy<-b8!tC}V&cyax(r7;8en>OK?FM=n|;lCv3-gA7O=`ZHn@v>ZBTCRFU F{R@Y~H-rEH literal 0 HcmV?d00001 diff --git a/cocktail_list/models.py b/cocktail_list/models.py index d3fdd77..dbe3fe7 100644 --- a/cocktail_list/models.py +++ b/cocktail_list/models.py @@ -26,12 +26,13 @@ class Ingredienti(models.Model): ('90ML', '90 ml'), ('95ML', '95 ml'), ('100ML', '100 ml'), - ('1Goccia', '1 goccia'), - ('2Gocce', '2 goccie'), - ('3Gocce', '3 goccie'), - ('4Gocce', '4 goccie'), - ('5Gocce', '5 goccie'), + ('1 Goccia', '1 goccia'), + ('2 Gocce', '2 goccie'), + ('3 Gocce', '3 goccie'), + ('4 Gocce', '4 goccie'), + ('5 Gocce', '5 goccie'), ('Cubetti', '3 Cubetti'), + ('Spruzzo', '1 Spruzzo'), ] quantitá = models.CharField(max_length=30,choices=quantitá_scelta,default="5ML") @@ -42,9 +43,6 @@ class Ingredienti(models.Model): verbose_name = "Ingrediente" verbose_name_plural = "Ingredienti" - - - class Cocktail(models.Model): ingredienti = models.ManyToManyField(Ingredienti) nome_cocktail = models.CharField(max_length=120) @@ -54,7 +52,7 @@ class Cocktail(models.Model): immagine_cocktail = models.ImageField(upload_to="cocktail_img",blank=True,null=True) def __str__(self): - return self.nome_cocktail + return f"{self.nome_cocktail}" def get_absolute_url(self): return reverse('cocktail', kwargs={'nome_cocktail': self.nome_cocktail}) diff --git a/cocktail_list/templates/cerca.html b/cocktail_list/templates/cerca.html new file mode 100644 index 0000000..8806003 --- /dev/null +++ b/cocktail_list/templates/cerca.html @@ -0,0 +1,40 @@ +{% extends "base.html" %} +{% load static %} + +{% block css %} + + + +{% endblock css %} + +{% block content %} +{% if cocktail %} +

In totale nel nostro Salone Bar abbiamo trovato {{ cocktail.count }} cocktails {% if cocktail.count == 1 %} che corrisponde {% else %} che corrispondono {% endif %} alla tua ricerca

+{% for cocktails in cocktail %} + + {% if forloop.first %}
{% endif %} + + {% if forloop.counter|divisibleby:"3" or forloop.last %} +
+ {% endif %} + {% if forloop.counter|divisibleby:"3" and not forloop.last %} +
+ {% endif %} + {% endfor %} +
+ {% endif %} + {% if ingrediente %} +

HELLO

+ {% endif %} +{% endblock content %} \ No newline at end of file diff --git a/cocktail_list/templates/cocktail.html b/cocktail_list/templates/cocktail.html index b3f3d47..6db8d05 100644 --- a/cocktail_list/templates/cocktail.html +++ b/cocktail_list/templates/cocktail.html @@ -1,5 +1,5 @@ {% extends "base.html" %} - +{% load static %} {% block css %} + {% endblock css %} diff --git a/cocktail_list/templates/homepage.html b/cocktail_list/templates/homepage.html index 16a80b0..06816d4 100644 --- a/cocktail_list/templates/homepage.html +++ b/cocktail_list/templates/homepage.html @@ -1,31 +1,17 @@ {% extends "base.html" %} +{% load static %} + +{% block css %} + + + +{% endblock css %} + {% block content %} +

In totale nel nostro Salone Bar abbiamo {{ lista_cocktail.count }}

{% for cocktail in lista_cocktail %} - {% block css %} - - - {% endblock css %} {% if forloop.first %}
{% endif %}
diff --git a/cocktail_list/templates/random_cocktail.html b/cocktail_list/templates/random_cocktail.html new file mode 100644 index 0000000..583e71b --- /dev/null +++ b/cocktail_list/templates/random_cocktail.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} +{% load static %} + +{% block css %} + + + +{% endblock css %} + +{% block content %} + {% for cocktail in random_cocktail %} + {% if forloop.first %} + {% endif %} + {% if forloop.counter|divisibleby:"3" and not forloop.last %} +
+ {% endif %} + {% endfor %} +{% endblock content %} \ No newline at end of file diff --git a/cocktail_list/urls.py b/cocktail_list/urls.py index bba4c01..65f6fc9 100644 --- a/cocktail_list/urls.py +++ b/cocktail_list/urls.py @@ -1,7 +1,10 @@ from django.urls import path -from .views import homepage,cocktail +from .views import homepage,cocktail,cerca,random_cocktail urlpatterns = [ path("",homepage,name="Homepage"), path("cocktail//",cocktail,name="cocktail"), + path("cerca/",cerca,name="cerca"), + path("random_cocktail/",random_cocktail,name="random_cocktail") + ] \ No newline at end of file diff --git a/cocktail_list/views.py b/cocktail_list/views.py index fd61734..90da897 100644 --- a/cocktail_list/views.py +++ b/cocktail_list/views.py @@ -1,5 +1,6 @@ from django.shortcuts import render,get_object_or_404,redirect from .models import Cocktail,Ingredienti +import random # Create your views here. @@ -15,13 +16,23 @@ def cocktail(request,nome_cocktail): context = {"cocktail":cocktail} return render(request,"cocktail.html",context) + +def random_cocktail(request): + random_cocktail = Cocktail.objects.all() + number_of_cocktail = Cocktail.objects.all().count() + random_cocktail_list = random.randint(1,number_of_cocktail) + rand_cocktail = random.sample(list(random_cocktail),random_cocktail_list) + context = {"random_cocktail":rand_cocktail} + return render(request,"random_cocktail.html",context) + def cerca(request): if "q" in request.GET: querystring = request.GET.get("q") if len(querystring) == 0: return redirect("cerca/") + ingrediente = Cocktail.objects.filter(ingredienti__ingrediente__icontains=querystring).order_by("-nome_cocktail") cocktail = Cocktail.objects.filter(nome_cocktail__icontains=querystring).order_by("-nome_cocktail") - context = {"cocktail":cocktail} + context = {"querystring":querystring,"cocktail":cocktail,"ingrediente":ingrediente} return render(request,"cerca.html",context) else: return render(request,"cerca.html") diff --git a/db.sqlite3 b/db.sqlite3 index c3b4f7fa318c7b857266cbdad595160ea2fe0d08..bf36e984195bec7baae75616ef4e1e839867c1d4 100644 GIT binary patch delta 434 zcmZo@;A&{#njkG`%D}*&0mK|Y%m~CG6LpLkO*bYi;b#`*>YU6jpw7Z|j;nLCp+GoS zy|XAQgSxe2a(;4lNn&PBd`@O@iGhKENqk~yNq)SMfsuiMsgZfSp@pdhh@)#@s%vDf zU}#}wYGGw)sb^+nX=rZZEP~Y#V-!Qo;tkD#X2A?GQ!q5QGT=6~GBMIKF|#l?GTJOG z&B)5Z_mA%pe>mU1&58<(__+Ah7*rVZQp@Axryr17o+GV0}hAH90^x=Hs7hKXPO+HzjRXr%L8U^X2I?335@DY{G4AI9*f)C zGdB5`Bqrsgg0;4XB{6OfOJZ8bE5XTrmVvL3*MldKyMSvuR~6@Djt%T**=_^F>L8mC z<5h7_PsXN5uvUblSP{(W`ALlY2)@Gfc}a|!yudhk3)bo1nBX|wFp2TO_6-$G0qg*$ C2zwL& delta 205 zcmZo@;A&{#njkG`%)r2)0mK|Y%m~DO6LpLkjW;GN;b#`+7M{#5puSmA;VIWH?G~)u#<~ud@Ow+CNnU-#9V0pmI!=$&JJ%Lf3iMcVsZ2E