Commit 2df08a55 authored by Kirby Ezekiel Santos's avatar Kirby Ezekiel Santos

Added the ingredients list page which uses an empty Ingredients model

parent fe6632c2
# Generated by Django 3.0.4 on 2020-03-18 08:12
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Ingredient',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=40)),
('quantity', models.CharField(max_length=40)),
],
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Ingredient(models.Model):
name = models.CharField(max_length=40)
quantity = models.CharField(max_length=40)
def __str__(self):
return self.name
def __str__(self):
return self.quantity
from django.contrib import admin
from django.urls import path from django.urls import path
from .views import go_to_home_page from .views import HomePageView
from .views import IngredientsListView
urlpatterns = [ urlpatterns = [
path('', go_to_home_page), path('', HomePageView.as_view()),
path('ingredients-list', IngredientsListView.as_view())
] ]
from django.shortcuts import render from django.views.generic.base import TemplateView
from django.views.generic.list import ListView
# Create your views here. from .models import Ingredient
home_page = "home_page.html"
def go_to_home_page(request): class HomePageView(TemplateView):
return render(request, home_page) template_name = "home_page.html"
class IngredientsListView(ListView):
template_name = "ingredients_list.html"
emptyIngredient = Ingredient(
name="",
quantity=""
)
emptyIngredient.save()
queryset = Ingredient.objects.all()
context = {
"object_list": queryset
}
...@@ -11,22 +11,22 @@ ...@@ -11,22 +11,22 @@
<div> <div>
<h2 id="home_page_ingredients">Ingredients</h2> <h2 id="home_page_ingredients">Ingredients</h2>
<form> <form method="get" action="http://localhost:8000/ingredients-list">
<button type="button" id="button_to_ingredients">View available ingredients</button> <button type="submit" id="button_to_ingredients">View available ingredients</button>
</form> </form>
</div> </div>
<div> <div>
<h2 id="home_page_recipes">Recipes</h2> <h2 id="home_page_recipes">Recipes</h2>
<form> <form>
<button type="button" id="button_to_recipes">Go to recipes</button> <button type="submit" id="button_to_recipes">Go to recipes</button>
</form> </form>
</div> </div>
<div> <div>
<h2 id="home_page_orders">Orders</h2> <h2 id="home_page_orders">Orders</h2>
<form> <form>
<button type="button" id="button_to_orders">Check current orders</button> <button type="submit" id="button_to_orders">Check current orders</button>
</form> </form>
</div> </div>
</body> </body>
......
<!DOCTYPE html>
<html>
<head>
<title>Ingredients - List</title>
</head>
<body>
<div>
<h1 id="page_header">Ingredients - List</h1>
</div>
<div>
<table class="table">
<thead>
<tr>
<th>Ingredient</th>
<th></th>
</tr>
</thead>
<tbody>
{% for object in object_list %}
<tr>
<td>{{object.name}}</td>
<td>
<form>
<button type="submit">Go to detail</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment