Aggiunto Form Creazione Cocktail

master
Michael Vignotto 2020-06-04 21:53:18 +02:00
parent 3e330f88a5
commit 80b05dca53
14 changed files with 50 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@ -37,7 +37,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cocktail_list'
'cocktail_list',
'crispy_forms'
]
MIDDLEWARE = [
@ -82,6 +83,8 @@ DATABASES = {
}
}
CRISPY_TEMPLATE_PACK = 'bootstrap4'
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

View File

@ -19,6 +19,9 @@
<a href="{% url 'strumenti-list' %}">Strumenti</a>
<a href="{% url 'bicchieri-list' %}">Bicchieri</a>
<a href="{% url 'random_cocktail' %}"><i class="fas fa-glass-cheers mr-2" style="color: black;"></i>Random Cocktail</a>
{% if request.user.is_staff %}
<a href="{% url 'crea-cocktail' %}"><i class="fas fa-plus mr-2"></i>Crea Cocktail</a>
{% endif %}
<div class="search-container">
<form action="{% url 'cerca' %}">
<input type="text" placeholder="Cerca..." name="q">

Binary file not shown.

9
cocktail_list/forms.py Normal file
View File

@ -0,0 +1,9 @@
from django.forms import ModelForm
from .models import Cocktail
class CocktailForm(ModelForm):
class Meta:
model = Cocktail
fields = '__all__'

View File

@ -0,0 +1,16 @@
{% extends 'base.html' %}
{% load static %}
{% load crispy_forms_tags %}
{% block css %}
<link rel="stylesheet" href="{% static 'css/navbar_style.css' %}">
{% endblock css %}
{% block content %}
<form method="POST" enctype="multipart/form-data" class="mt-3">
{% csrf_token %}
{{ form|crispy }}
<div class="row no-gutters"><input type="submit" class="btn btn-outline-info mb-3 mx-auto" value="Crea Cocktail"></div>
</form>
{% endblock content %}

View File

@ -1,5 +1,5 @@
from django.urls import path
from .views import homepage,cocktail,cerca,random_cocktail,strumenti_cocktail,bicchieri_cocktail
from .views import homepage,cocktail,cerca,random_cocktail,strumenti_cocktail,bicchieri_cocktail,createCocktail
urlpatterns = [
path("",homepage,name="Homepage"),
@ -7,6 +7,7 @@ urlpatterns = [
path("cerca/",cerca,name="cerca"),
path("random_cocktail/",random_cocktail,name="random_cocktail"),
path("strumenti/",strumenti_cocktail,name="strumenti-list"),
path("bicchieri/",bicchieri_cocktail,name="bicchieri-list")
path("bicchieri/",bicchieri_cocktail,name="bicchieri-list"),
path("crea-cocktail/",createCocktail,name="crea-cocktail")
]

View File

@ -1,6 +1,8 @@
from django.shortcuts import render,get_object_or_404,redirect
from .models import Cocktail,Ingredienti,Strumenti,Bicchieri
from .forms import CocktailForm
import random
# Create your views here.
@ -73,4 +75,16 @@ def cerca(request):
context = {"querystring":querystring,"cocktail":cocktail,"ingrediente":searching_ingred}
return render(request,"cerca.html",context)
else:
return render(request,"cerca.html")
return render(request,"cerca.html")
def createCocktail(request):
if request.method == "POST":
form = CocktailForm(request.POST,request.FILES)
if form.is_valid():
cocktail = form.save()
return redirect("cocktail", nome_cocktail=cocktail.nome_cocktail)
else:
form = CocktailForm()
context = {"form":form}
return render(request,"crea_cocktail.html",context)

Binary file not shown.