commit 4ba636a9d3b15648b8dc1be7233647d397ae5ad8 Author: Thomas Schwery Date: Sun Feb 6 22:15:44 2022 +0100 feat: Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acfdee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +env +__pycache__ +*.sqlite3 diff --git a/djangotea/__init__.py b/djangotea/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangotea/asgi.py b/djangotea/asgi.py new file mode 100644 index 0000000..163624e --- /dev/null +++ b/djangotea/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for djangotea 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangotea.settings') + +application = get_asgi_application() diff --git a/djangotea/settings.py b/djangotea/settings.py new file mode 100644 index 0000000..636ba68 --- /dev/null +++ b/djangotea/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for djangotea project. + +Generated by 'django-admin startproject' using Django 4.0.2. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-de-2*zq9g3v5!bjit%^hh5=je_a6mk!sc4)r@+a3ubd*e^7x1a' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'tea.apps.TeaConfig', + 'wine.apps.WineConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'djangotea.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'djangotea.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.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/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + diff --git a/djangotea/urls.py b/djangotea/urls.py new file mode 100644 index 0000000..79cba3b --- /dev/null +++ b/djangotea/urls.py @@ -0,0 +1,23 @@ +"""djangotea URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.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 + +urlpatterns = [ + path('admin/', admin.site.urls), + path('tea/', include('tea.urls')), + path('wine/', include('wine.urls')), +] diff --git a/djangotea/wsgi.py b/djangotea/wsgi.py new file mode 100644 index 0000000..27859bf --- /dev/null +++ b/djangotea/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djangotea 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangotea.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..eae573e --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangotea.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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ab09bb7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Django==4.0.2 diff --git a/tea/__init__.py b/tea/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tea/admin.py b/tea/admin.py new file mode 100644 index 0000000..872e4f0 --- /dev/null +++ b/tea/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Tea, Company + +admin.site.register(Tea) +admin.site.register(Company) diff --git a/tea/apps.py b/tea/apps.py new file mode 100644 index 0000000..e33e935 --- /dev/null +++ b/tea/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TeaConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'tea' diff --git a/tea/migrations/0001_initial.py b/tea/migrations/0001_initial.py new file mode 100644 index 0000000..ce75833 --- /dev/null +++ b/tea/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 4.0.2 on 2022-02-05 22:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Company', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('website', models.CharField(max_length=200)), + ], + ), + migrations.CreateModel( + name='Tea', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('tea_type', models.CharField(choices=[('infusion', 'Infusion'), ('black-tea', 'Thé noir'), ('green-tea', 'Thé vert'), ('white-tea', 'Thé blanc'), ('rooibos', 'Rooibos'), ('fruit', 'Tisane aux fruits'), ('mate', 'Maté')], max_length=20)), + ('conditioning', models.CharField(choices=[('loose', 'En vrac'), ('bag', 'En sachet')], max_length=20)), + ('ingredients', models.TextField(max_length=1024)), + ('tea_quantity', models.DecimalField(blank=True, decimal_places=1, max_digits=5, null=True)), + ('tea_quantity_type', models.CharField(choices=[('cs-l', 'cs/lt'), ('cc-dl', 'cc/dl'), ('cc-l', 'cc/lt'), ('pc-l', 'pc/lt')], default='cc-l', max_length=20)), + ('tea_time_from', models.PositiveSmallIntegerField()), + ('tea_time_to', models.PositiveSmallIntegerField()), + ('tea_time_type', models.CharField(choices=[('min', 'min')], default='min', max_length=20)), + ('url', models.URLField(blank=True, max_length=1024, null=True)), + ('available', models.BooleanField()), + ('comment', models.TextField(blank=True, null=True)), + ('company', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='tea.company')), + ], + ), + ] diff --git a/tea/migrations/__init__.py b/tea/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tea/models.py b/tea/models.py new file mode 100644 index 0000000..809c14d --- /dev/null +++ b/tea/models.py @@ -0,0 +1,53 @@ +from django.db import models + +class Company(models.Model): + name = models.CharField(max_length=200) + website = models.CharField(max_length=200) + + def __str__(self): + return self.name + +class Tea(models.Model): + + TEA_CONDITIONING = [ + ('loose', 'En vrac'), + ('bag', 'En sachet'), + ] + + TEA_TYPE = [ + ('infusion', 'Infusion'), + ('black-tea', 'Thé noir'), + ('green-tea', 'Thé vert'), + ('white-tea', 'Thé blanc'), + ('rooibos', 'Rooibos'), + ('fruit', 'Tisane aux fruits'), + ('mate', 'Maté'), + ] + + QUANTITY_UNITS = [ + ('cs-l', 'cs/lt'), + ('cc-dl', 'cc/dl'), + ('cc-l', 'cc/lt'), + ('pc-l', 'pc/lt'), + ] + + TIME_UNITS = [ + ('min', 'min'), + ] + + name = models.CharField(max_length=200) + company = models.ForeignKey(Company, on_delete=models.PROTECT, null=True) + tea_type = models.CharField(max_length=20, choices=TEA_TYPE) + conditioning = models.CharField(max_length=20, choices=TEA_CONDITIONING) + ingredients = models.TextField(max_length=1024) + tea_quantity = models.DecimalField(max_digits=5, decimal_places=1, null=True, blank=True) + tea_quantity_type = models.CharField(max_length=20, choices=QUANTITY_UNITS, default='cc-l') + tea_time_from = models.PositiveSmallIntegerField() + tea_time_to = models.PositiveSmallIntegerField() + tea_time_type = models.CharField(max_length=20, choices=TIME_UNITS, default='min') + url = models.URLField(max_length=1024, null=True, blank=True) + available = models.BooleanField() + comment = models.TextField(null=True, blank=True) + + def __str__(self): + return self.company.name + " - " + self.name diff --git a/tea/templates/tea/base.html b/tea/templates/tea/base.html new file mode 100644 index 0000000..ab9665f --- /dev/null +++ b/tea/templates/tea/base.html @@ -0,0 +1,21 @@ + + + + + + + Django Tea + + +
+
+
+

Django Tea

+
+ {% block content %} + {% endblock %} +
+
+
+ + diff --git a/tea/templates/tea/detail.html b/tea/templates/tea/detail.html new file mode 100644 index 0000000..fc64415 --- /dev/null +++ b/tea/templates/tea/detail.html @@ -0,0 +1,31 @@ +{% extends 'tea/base.html' %} + +{% block content %} +

{{ tea.company.name }} - {{ tea.name }} ({{ tea.tea_type }})

+ +

+{{ tea.ingredients }} +

+ +
+ {% if tea.tea_quantity %} +
Quantité
+
+ {{ tea.tea_quantity }} {{ tea.tea_quantity_type }} +
+ {% endif %} + +
Temps
+
+ {{ tea.tea_time_from }}-{{ tea.tea_time_to }} {{ tea.tea_time_type }} +
+ + {% if tea.url %} +
Page web
+
+ {{ tea.url }} +
+ {% endif %} +
+ +{% endblock %} diff --git a/tea/templates/tea/index.html b/tea/templates/tea/index.html new file mode 100644 index 0000000..4437474 --- /dev/null +++ b/tea/templates/tea/index.html @@ -0,0 +1,14 @@ +{% extends 'tea/base.html' %} + +{% block content %} +{% for company in company_list %} +

{{ company.name }}

+ +{% endfor %} +{% endblock %} diff --git a/tea/tests.py b/tea/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tea/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tea/urls.py b/tea/urls.py new file mode 100644 index 0000000..18bdbb2 --- /dev/null +++ b/tea/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +app_name = 'tea' +urlpatterns = [ + path('', views.IndexView.as_view(), name='index'), + path('/', views.DetailView.as_view(), name='detail'), +] diff --git a/tea/views.py b/tea/views.py new file mode 100644 index 0000000..e4cac13 --- /dev/null +++ b/tea/views.py @@ -0,0 +1,14 @@ +from django.http import HttpResponse +from django.shortcuts import render, get_object_or_404 +from django.views import generic + +from .models import Tea, Company + +class IndexView(generic.ListView): + model = Company + template_name = 'tea/index.html' + + +class DetailView(generic.DetailView): + model = Tea + template_name = 'tea/detail.html' diff --git a/wine/__init__.py b/wine/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wine/admin.py b/wine/admin.py new file mode 100644 index 0000000..b30fb0b --- /dev/null +++ b/wine/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin + + +from .models import Classification, Variety, Winery, Storage, Wine, Millesime + + +class MillesimeInline(admin.TabularInline): + model = Millesime + +class WineAdmin(admin.ModelAdmin): + inlines = [MillesimeInline] + +admin.site.register(Classification) +admin.site.register(Variety) +admin.site.register(Winery) +admin.site.register(Storage) +admin.site.register(Wine, WineAdmin) diff --git a/wine/apps.py b/wine/apps.py new file mode 100644 index 0000000..07baf8f --- /dev/null +++ b/wine/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WineConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'wine' diff --git a/wine/migrations/0001_initial.py b/wine/migrations/0001_initial.py new file mode 100644 index 0000000..5cc0792 --- /dev/null +++ b/wine/migrations/0001_initial.py @@ -0,0 +1,66 @@ +# Generated by Django 4.0.2 on 2022-02-06 21:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Classification', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ], + ), + migrations.CreateModel( + name='Storage', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ], + ), + migrations.CreateModel( + name='Variety', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('classification', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='wine.classification')), + ], + ), + migrations.CreateModel( + name='Winery', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('website', models.URLField(blank=True, null=True)), + ], + ), + migrations.CreateModel( + name='Wine', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('comment', models.TextField(blank=True, null=True)), + ('storage', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='wine.storage')), + ('variety', models.ManyToManyField(to='wine.Variety')), + ('winery', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='wine.winery')), + ], + ), + migrations.CreateModel( + name='Millesime', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('year', models.PositiveIntegerField()), + ('size', models.CharField(choices=[('piccolo', 'Piccolo (0,20 Litres)'), ('quart', 'Quart (0,25 Litres)'), ('demi', 'Demi (0,375 Litres)'), ('medium', 'Médium (0,50 Litres)'), ('bouteille', 'Bouteille (0,75 Litres)'), ('magnum', 'Magnum (1,5 Litres)'), ('jeroboam', 'Jéroboam (3 Litres)'), ('rehoboam', 'Réhoboam (4,5 Litres)'), ('mathusalem', 'Mathusalem (6 Litres)'), ('salmanazar', 'Salmanazar (9 Litres)'), ('balthazar', 'Balthazar (12 Litres)'), ('nabuchodonosor', 'Nabuchodonosor (15 Litres)'), ('melchior', 'Melchior (18 Litres)'), ('souverain', 'Souverain (26,25 Litres)'), ('primat', 'Primat (27 Litres)'), ('midas', 'Midas (30 Litres)')], default='bouteille', max_length=20)), + ('available', models.SmallIntegerField()), + ('wine', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wine.wine')), + ], + ), + ] diff --git a/wine/migrations/__init__.py b/wine/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wine/models.py b/wine/models.py new file mode 100644 index 0000000..ebb884a --- /dev/null +++ b/wine/models.py @@ -0,0 +1,67 @@ +from django.db import models + + +class Classification(models.Model): + name = models.CharField(max_length=200) + + def __str__(self): + return self.name + +class Variety(models.Model): + name = models.CharField(max_length=200) + classification = models.ForeignKey(Classification, on_delete=models.PROTECT) + + def __str__(self): + return self.name + +class Winery(models.Model): + name = models.CharField(max_length=200) + website = models.URLField(max_length=200, blank=True, null=True) + + def __str__(self): + return self.name + +class Storage(models.Model): + name = models.CharField(max_length=200) + + def __str__(self): + return self.name + +class Wine(models.Model): + name = models.CharField(max_length=200) + variety = models.ManyToManyField(Variety) + winery = models.ForeignKey(Winery, on_delete=models.PROTECT) + storage = models.ForeignKey(Storage, on_delete=models.PROTECT) + comment = models.TextField(null=True, blank=True) + + def __str__(self): + return self.winery.name + " - " + self.name + +class Millesime(models.Model): + + BOTTLE_SIZES = [ + ('piccolo', 'Piccolo (0,20 Litres)'), + ('quart', 'Quart (0,25 Litres)'), + ('demi', 'Demi (0,375 Litres)'), + ('medium', 'Médium (0,50 Litres)'), + ('bouteille', 'Bouteille (0,75 Litres)'), + ('magnum', 'Magnum (1,5 Litres)'), + ('jeroboam', 'Jéroboam (3 Litres)'), + ('rehoboam', 'Réhoboam (4,5 Litres)'), + ('mathusalem', 'Mathusalem (6 Litres)'), + ('salmanazar', 'Salmanazar (9 Litres)'), + ('balthazar', 'Balthazar (12 Litres)'), + ('nabuchodonosor', 'Nabuchodonosor (15 Litres)'), + ('melchior', 'Melchior (18 Litres)'), + ('souverain', 'Souverain (26,25 Litres)'), + ('primat', 'Primat (27 Litres)'), + ('midas', 'Midas (30 Litres)'), + ] + + year = models.PositiveIntegerField() + wine = models.ForeignKey(Wine, on_delete=models.CASCADE) + size = models.CharField(max_length=20, choices=BOTTLE_SIZES, default='bouteille') + available = models.SmallIntegerField() + + def __str__(self): + return "%i" % self.year diff --git a/wine/templates/wine/base.html b/wine/templates/wine/base.html new file mode 100644 index 0000000..51d2d4c --- /dev/null +++ b/wine/templates/wine/base.html @@ -0,0 +1,21 @@ + + + + + + + Django Wine + + +
+
+
+

Django Wine

+
+ {% block content %} + {% endblock %} +
+
+
+ + diff --git a/wine/templates/wine/detail.html b/wine/templates/wine/detail.html new file mode 100644 index 0000000..33c0999 --- /dev/null +++ b/wine/templates/wine/detail.html @@ -0,0 +1,55 @@ +{% extends 'wine/base.html' %} + +{% block content %} +

{{ wine.winery.name }} - {{ wine.name }}

+ +

+{{ wine.comment }} +

+ +
+ +
Cépages
+
+
    + {% for variety in wine.variety.all %} +
  • {{ variety.name }}
  • + {% endfor %} +
+
+
Cave
+
+ {{ wine.winery.name }} +
+ +
Stockage
+
+ {{ wine.storage.name }} +
+
+ + + + + + + + + + + + + {% for millesime in wine.millesime_set.all %} + + + + + + + {% endfor %} + +
AnnéeTailleBouteillesOperation
{{ millesime.year }}{{ millesime.available }}{{ millesime.get_size_display }} + Edit +
+ +{% endblock %} diff --git a/wine/templates/wine/index.html b/wine/templates/wine/index.html new file mode 100644 index 0000000..33cffca --- /dev/null +++ b/wine/templates/wine/index.html @@ -0,0 +1,12 @@ +{% extends 'wine/base.html' %} + +{% block content %} +{% for winery in winery_list %} +

{{ winery.name }}

+ +{% endfor %} +{% endblock %} diff --git a/wine/tests.py b/wine/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/wine/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/wine/urls.py b/wine/urls.py new file mode 100644 index 0000000..545655c --- /dev/null +++ b/wine/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import views + +app_name = 'wine' +urlpatterns = [ + path('', views.IndexView.as_view(), name='index'), + path('/', views.DetailView.as_view(), name='detail'), + path('takeout/', views.takeoutBottle, name='takeout'), +] diff --git a/wine/views.py b/wine/views.py new file mode 100644 index 0000000..e38514f --- /dev/null +++ b/wine/views.py @@ -0,0 +1,25 @@ +from django.db.models import F +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render, get_object_or_404 +from django.urls import reverse +from django.views import generic + +from .models import Wine, Winery, Millesime + +class IndexView(generic.ListView): + model = Winery + template_name = 'wine/index.html' + + def get_queryset(self): + return Winery.objects.order_by('name') + + +class DetailView(generic.DetailView): + model = Wine + template_name = 'wine/detail.html' + +def takeoutBottle(request, millesime_id): + millesime = get_object_or_404(Millesime, pk=millesime_id) + millesime.available = F('available') - 1 + millesime.save() + return HttpResponseRedirect(reverse('wine:detail', args=(millesime.wine.id,)))