added some views
This commit is contained in:
parent
f046acc94d
commit
dd23556410
|
@ -18,5 +18,5 @@ from django.urls import include, path
|
|||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('inventory/', include('inventory.urls')),
|
||||
path('', include('inventory.urls')),
|
||||
]
|
||||
|
|
|
@ -27,8 +27,16 @@ UNITS = (
|
|||
|
||||
|
||||
#class ShoppingList(models.Model):
|
||||
# - pantryitems < min_quantity in pantryitemlists
|
||||
# - shoppinglistitems
|
||||
# - user ?
|
||||
# info
|
||||
# quantity
|
||||
# unit
|
||||
# name
|
||||
|
||||
class PantryItem(models.Model):
|
||||
# user?
|
||||
name = models.CharField(max_length=200)
|
||||
category = models.CharField(max_length=200, choices=CATEGORIES)
|
||||
min_quantity = models.IntegerField(default=1) #, decimal_places=3, max_digits=32)
|
||||
|
@ -39,6 +47,7 @@ class PantryItem(models.Model):
|
|||
return self.name
|
||||
|
||||
class PantryItemLine(models.Model):
|
||||
# user?
|
||||
pantry_item = models.ForeignKey(PantryItem, on_delete=models.PROTECT, default='UN' )
|
||||
quantity = models.IntegerField(default=1)
|
||||
expiry_date = models.DateField(null=True, blank=True)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<title>Pantry Inventory</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<h1 class="mt-2">Pantry Inventory</h1>
|
||||
<hr class="mt-0 mb-4">
|
||||
{% block content %}
|
||||
BASE TEMPLATE
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
{% extends 'inventory/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
{% if pis %}
|
||||
<ul>
|
||||
{% for pi in pis %}
|
||||
<li><a href="{% url 'im:pantryitemlinedetail' pi.id %}">{{ pi}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No Pantry Items are available.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -0,0 +1,8 @@
|
|||
{% extends 'inventory/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<a href="{% url 'im:eat' %} ">eat</a>
|
||||
<a href="{% url 'im:shoppinglist' %} ">shoppinglist</a>
|
||||
<a href="{% url 'im:expirations' %} ">expirations</a>
|
||||
<a href="{% url 'admin:index' %} ">admin</a>
|
||||
{% endblock %}
|
|
@ -0,0 +1,5 @@
|
|||
{% extends 'inventory/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
{{ pantryitemline }}
|
||||
{% endblock %}
|
|
@ -1,6 +1,15 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'im'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('eat/', views.eat, name='eat'),
|
||||
path('shoppinglist/', views.shoppinglist, name='shoppinglist'),
|
||||
# TODO: add exiperes before X date?
|
||||
# TODO: add categories
|
||||
# TODO: add pantry item selection
|
||||
path('expirations/', views.Expirations.as_view(), name='expirations'),
|
||||
#TODO: later: add edit views instead of admin edits
|
||||
path('item/<int:pk>/', views.DetailView.as_view(), name='pantryitemlinedetail'),
|
||||
]
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
from django.views import generic
|
||||
|
||||
from .models import PantryItemLine
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("TODO: implement web interface")
|
||||
return render(request, "inventory/index.html")
|
||||
|
||||
|
||||
def eat(request):
|
||||
return HttpResponse("TODO: implement web interface voor eten")
|
||||
|
||||
|
||||
def shoppinglist(request):
|
||||
return HttpResponse("TODO: implement web interface voor shoppinglijst")
|
||||
|
||||
|
||||
class Expirations(generic.ListView):
|
||||
template_name = "inventory/expirations.html"
|
||||
context_object_name = 'pis'
|
||||
|
||||
def get_queryset(self):
|
||||
return PantryItemLine.objects.order_by('-expiry_date')
|
||||
|
||||
|
||||
class DetailView(generic.DetailView):
|
||||
model = PantryItemLine
|
||||
|
|
Loading…
Reference in New Issue