Aggiunta Funzionalitá Random per Cocktail
parent
65dccb0581
commit
9d73d299da
Binary file not shown.
|
@ -123,4 +123,6 @@ STATIC_URL = '/static/'
|
|||
|
||||
MEDIA_ROOT = (os.path.join(BASE_DIR, 'cocktail/cocktail_img'))
|
||||
|
||||
MEDIA_URL = "/img/"
|
||||
MEDIA_URL = "/img/"
|
||||
|
||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static-storage')]
|
|
@ -7,12 +7,25 @@
|
|||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
|
||||
{% block css %}
|
||||
|
||||
{% endblock css %}
|
||||
<title>{% block title %} {% endblock title %}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<a class="active" href="{% url 'Homepage' %}">Home</a>
|
||||
<a href="#about">Strumenti</a>
|
||||
<a href="#about">Bicchieri</a>
|
||||
<a href="{% url 'random_cocktail' %}">Random Cocktail</a>
|
||||
<div class="search-container">
|
||||
<form action="{% url 'cerca' %}">
|
||||
<input type="text" placeholder="Cerca..." name="q">
|
||||
<button type="submit"><i class="fa fa-search"></i></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
|
||||
|
@ -24,5 +37,6 @@
|
|||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-26 17:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cocktail_list', '0002_cocktail_immagine_cocktail'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ingredienti',
|
||||
name='quantitá',
|
||||
field=models.CharField(choices=[('5ML', '5 ml'), ('10ML', '10 ml'), ('15ML', '15 ml'), ('20ML', '20 ml'), ('25ML', '25 ml'), ('30ML', '30 ml'), ('35ML', '35 ml'), ('40ML', '40 ml'), ('45ML', '45 ml'), ('50ML', '50 ml'), ('55ML', '55 ml'), ('60ML', '60 ml'), ('65ML', '65 ml'), ('70ML', '70 ml'), ('75ML', '75 ml'), ('80ML', '80 ml'), ('85ML', '85 ml'), ('90ML', '90 ml'), ('95ML', '95 ml'), ('100ML', '100 ml'), ('1Goccia', '1 goccia'), ('2Gocce', '2 goccie'), ('3Gocce', '3 goccie'), ('4Gocce', '4 goccie'), ('5Gocce', '5 goccie'), ('Cubetti', '3 Cubetti'), ('Spruzzo', '1 Spruzzo')], default='5ML', max_length=30),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-27 18:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cocktail_list', '0003_auto_20200526_1705'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ingredienti',
|
||||
name='quantitá',
|
||||
field=models.CharField(choices=[('5ML', '5 ml'), ('10ML', '10 ml'), ('15ML', '15 ml'), ('20ML', '20 ml'), ('25ML', '25 ml'), ('30ML', '30 ml'), ('35ML', '35 ml'), ('40ML', '40 ml'), ('45ML', '45 ml'), ('50ML', '50 ml'), ('55ML', '55 ml'), ('60ML', '60 ml'), ('65ML', '65 ml'), ('70ML', '70 ml'), ('75ML', '75 ml'), ('80ML', '80 ml'), ('85ML', '85 ml'), ('90ML', '90 ml'), ('95ML', '95 ml'), ('100ML', '100 ml'), ('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')], default='5ML', max_length=30),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
|
@ -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})
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/navbar_style.css' %}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
|
||||
{% block content %}
|
||||
{% if cocktail %}
|
||||
<h1 class="text-center">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>
|
||||
{% for cocktails in cocktail %}
|
||||
<!-- {{ cocktail.ingredienti.all }}
|
||||
{{ cocktail.nome_cocktail }} -->
|
||||
{% if forloop.first %} <div class="row"> {% endif %}
|
||||
<div class="col-lg-4 my-3">
|
||||
<a href="{{ cocktails.get_absolute_url }}">
|
||||
<div class="card h-100 my-1 border border-info">
|
||||
<div class="card-img-top"><img src="{{ cocktails.immagine_cocktail.url }}" class="img-fluid" alt="{{ cocktails.nome_cocktail }}"></div>
|
||||
<div class="text_on_image">{{ cocktails.nome_cocktail }}</div>
|
||||
<div class="card-body py-0">
|
||||
<p class="mt-2 mb-0 py-3 text-center">{{ cocktails.ingredienti.all|join:"," }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% if forloop.counter|divisibleby:"3" or forloop.last %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if forloop.counter|divisibleby:"3" and not forloop.last %}
|
||||
<div class="row">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% if ingrediente %}
|
||||
<h1>HELLO</h1>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load static %}
|
||||
{% block css %}
|
||||
<style>
|
||||
.widgetcocktail {
|
||||
|
@ -15,6 +15,7 @@
|
|||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="{% static 'css/navbar_style.css' %}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
|
||||
|
|
|
@ -1,31 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/navbar_style.css' %}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="text-center">In totale nel nostro Salone Bar abbiamo {{ lista_cocktail.count }} <i class="fas fa-cocktail"></i> </h1>
|
||||
{% for cocktail in lista_cocktail %}
|
||||
<!-- {{ cocktail.ingredienti.all }}
|
||||
{{ cocktail.nome_cocktail }} -->
|
||||
{% block css %}
|
||||
<style>
|
||||
.text_on_image{
|
||||
color:white;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-transform: uppercase;
|
||||
font-size: 2.5em;
|
||||
font-family: 'Faster One', cursive;
|
||||
}
|
||||
a
|
||||
{
|
||||
color: inherit;
|
||||
text-decoration: none!important;
|
||||
}
|
||||
a:hover{
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
{% if forloop.first %} <div class="row"> {% endif %}
|
||||
<div class="col-lg-4 my-3">
|
||||
<a href="{{ cocktail.get_absolute_url }}">
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/navbar_style.css' %}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
|
||||
{% block content %}
|
||||
{% for cocktail in random_cocktail %}
|
||||
{% if forloop.first %} <div class="row"> {% endif %}
|
||||
<div class="col-lg-4 my-3">
|
||||
<a href="{{ cocktail.get_absolute_url }}">
|
||||
<div class="card h-100 my-1 border border-info">
|
||||
<div class="card-img-top"><img src="{{ cocktail.immagine_cocktail.url }}" class="img-fluid" alt="{{ cocktail.nome_cocktail }}"></div>
|
||||
<div class="text_on_image">{{ cocktail.nome_cocktail }}</div>
|
||||
<div class="card-body py-0">
|
||||
<p class="mt-2 mb-0 py-3 text-center">{{ cocktail.ingredienti.all|join:"," }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% if forloop.counter|divisibleby:"3" or forloop.last %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if forloop.counter|divisibleby:"3" and not forloop.last %}
|
||||
<div class="row">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
|
@ -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/<nome_cocktail>/",cocktail,name="cocktail"),
|
||||
path("cerca/",cerca,name="cerca"),
|
||||
path("random_cocktail/",random_cocktail,name="random_cocktail")
|
||||
|
||||
]
|
|
@ -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")
|
||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -0,0 +1,67 @@
|
|||
.topnav {
|
||||
overflow: hidden;
|
||||
background-color: #e9e9e9;
|
||||
}
|
||||
|
||||
.topnav a {
|
||||
float: left;
|
||||
display: block;
|
||||
color: black;
|
||||
text-align: center;
|
||||
padding: 14px 16px;
|
||||
text-decoration: none;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.topnav a:hover {
|
||||
background-color: #ddd;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.topnav a.active {
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.topnav .search-container {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.topnav input[type=text] {
|
||||
padding: 6px;
|
||||
margin-top: 8px;
|
||||
font-size: 17px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.topnav .search-container button {
|
||||
float: right;
|
||||
padding: 6px 10px;
|
||||
margin-top: 8px;
|
||||
margin-right: 16px;
|
||||
background: #ddd;
|
||||
font-size: 17px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.topnav .search-container button:hover {
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
.topnav .search-container {
|
||||
float: none;
|
||||
}
|
||||
.topnav a, .topnav input[type=text], .topnav .search-container button {
|
||||
float: none;
|
||||
display: block;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 14px;
|
||||
}
|
||||
.topnav input[type=text] {
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.text_on_image{
|
||||
color:white;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-transform: uppercase;
|
||||
font-size: 2.5em;
|
||||
font-family: 'Faster One', cursive;
|
||||
}
|
||||
a
|
||||
{
|
||||
color: inherit;
|
||||
text-decoration: none!important;
|
||||
}
|
||||
a:hover{
|
||||
color: inherit;
|
||||
}
|
Loading…
Reference in New Issue