first commit
commit
65dccb0581
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for cocktail project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cocktail.settings')
|
||||
|
||||
application = get_asgi_application()
|
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
|
@ -0,0 +1,126 @@
|
|||
"""
|
||||
Django settings for cocktail project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.0.5.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'cx%6wl9g2)m3tq-^2$7(tyc4b99bl-a*kjseiz1s+1jb!qflkp'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'cocktail_list'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'cocktail.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, 'cocktail/templates'),
|
||||
os.path.join(BASE_DIR, 'cocktail_list/templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'cocktail.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'it'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
MEDIA_ROOT = (os.path.join(BASE_DIR, 'cocktail/cocktail_img'))
|
||||
|
||||
MEDIA_URL = "/img/"
|
|
@ -0,0 +1,28 @@
|
|||
<!doctype html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
|
||||
{% block css %}
|
||||
|
||||
{% endblock css %}
|
||||
<title>{% block title %} {% endblock title %}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
|
||||
{% endblock content %}
|
||||
</div>
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
"""cocktail URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include,path
|
||||
from django.conf.urls.static import static
|
||||
from django.conf import settings
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('cocktail_list.urls'))
|
||||
]
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for cocktail project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cocktail.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
from .models import Ingredienti,Cocktail
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Ingredienti)
|
||||
admin.site.register(Cocktail)
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CocktailListConfig(AppConfig):
|
||||
name = 'cocktail_list'
|
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-24 15:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Ingredienti',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('ingrediente', models.CharField(max_length=100)),
|
||||
('quantitá', 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')], default='5ML', max_length=30)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Ingrediente',
|
||||
'verbose_name_plural': 'Ingredienti',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Cocktail',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('nome_cocktail', models.CharField(max_length=120)),
|
||||
('preparazione', models.TextField()),
|
||||
('storia', models.TextField()),
|
||||
('curiositá', models.TextField()),
|
||||
('ingredienti', models.ManyToManyField(to='cocktail_list.Ingredienti')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Cocktail',
|
||||
'verbose_name_plural': 'Cocktails',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-24 15:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cocktail_list', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='cocktail',
|
||||
name='immagine_cocktail',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='cocktail_img'),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,64 @@
|
|||
from django.db import models
|
||||
from django.urls import reverse
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Ingredienti(models.Model):
|
||||
ingrediente = models.CharField(max_length=100)
|
||||
quantitá_scelta = [
|
||||
('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'),
|
||||
]
|
||||
quantitá = models.CharField(max_length=30,choices=quantitá_scelta,default="5ML")
|
||||
|
||||
def __str__(self):
|
||||
return self.ingrediente
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Ingrediente"
|
||||
verbose_name_plural = "Ingredienti"
|
||||
|
||||
|
||||
|
||||
|
||||
class Cocktail(models.Model):
|
||||
ingredienti = models.ManyToManyField(Ingredienti)
|
||||
nome_cocktail = models.CharField(max_length=120)
|
||||
preparazione = models.TextField()
|
||||
storia = models.TextField()
|
||||
curiositá = models.TextField()
|
||||
immagine_cocktail = models.ImageField(upload_to="cocktail_img",blank=True,null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.nome_cocktail
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('cocktail', kwargs={'nome_cocktail': self.nome_cocktail})
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Cocktail"
|
||||
verbose_name_plural = "Cocktails"
|
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
.widgetcocktail {
|
||||
border: 2px solid black;
|
||||
border-radius: 20px;
|
||||
text-transform: uppercase;
|
||||
font-family: 'Faster One', cursive;
|
||||
color: black;
|
||||
margin: auto;
|
||||
}
|
||||
img {
|
||||
border-radius: 50px;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Faster+One&display=swap" rel="stylesheet">
|
||||
{% endblock css %}
|
||||
|
||||
|
||||
{% block title %}
|
||||
COCKTAIL | {{ cocktail.nome_cocktail }}
|
||||
{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="widgetcocktail">
|
||||
<div class="text-center"><h3>{{ cocktail.nome_cocktail }}</h3></div>
|
||||
<div class="row"><img src="{{ cocktail.immagine_cocktail.url }}" class="img-fluid mx-auto" alt="{{ cocktail.nome_cocktail }}"></div>
|
||||
<p class="text-center">{{ cocktail.ingredienti.all|join:"," }}</p>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -0,0 +1,48 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% 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 }}">
|
||||
<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 %}
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
from .views import homepage,cocktail
|
||||
|
||||
urlpatterns = [
|
||||
path("",homepage,name="Homepage"),
|
||||
path("cocktail/<nome_cocktail>/",cocktail,name="cocktail"),
|
||||
]
|
|
@ -0,0 +1,27 @@
|
|||
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")
|
Binary file not shown.
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cocktail.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue