Aggiunto Form Creazione Cocktail
parent
3e330f88a5
commit
80b05dca53
Binary file not shown.
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 |
|
@ -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
|
||||
|
|
|
@ -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.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
from django.forms import ModelForm
|
||||
from .models import Cocktail
|
||||
|
||||
class CocktailForm(ModelForm):
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Cocktail
|
||||
fields = '__all__'
|
|
@ -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 %}
|
|
@ -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")
|
||||
|
||||
]
|
|
@ -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.
|
||||
|
||||
|
||||
|
@ -74,3 +76,15 @@ def cerca(request):
|
|||
return render(request,"cerca.html",context)
|
||||
else:
|
||||
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)
|
||||
|
||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue