Commit e4fc58d5 authored by Julia Santos's avatar Julia Santos

Trying to allow users to add items

parent ad9dcc73
myenv/
*.pyc
db.sqlite3
__pycache__
\ No newline at end of file
__pycache__
media/upload/
\ No newline at end of file
from django import forms
import datetime
from django.core.validators import FileExtensionValidator
class LoginForm(forms.Form):
......@@ -10,4 +11,13 @@ class ProductTypeForm(forms.Form):
Product_Category = forms.CharField(max_length = 255)
Product_Description = forms.CharField(max_length = 255, required = False)
To_Buy = forms.BooleanField(initial = False, required = False)
Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ])
\ No newline at end of file
Icon = forms.ImageField(validators=[FileExtensionValidator( ['png','jpg'] ) ])
class AddItemForm(forms.Form):
Item_Quantity = forms.FloatField()
Quantity_Unit = forms.CharField(max_length = 255)
Item_Description = forms.CharField(max_length = 255, required = False)
Purchase_Date = forms.DateField(initial = datetime.datetime.now().date())
Expiration_Date = forms.DateField()
#Is_Expired = forms.BooleanField(initial = False, required = False)
Is_Consumed = forms.BooleanField(initial = False, required = False)
<!DOCTYPE html>
<html lang="en">
{% load static %}
<link rel="stylesheet" href="{%static "sidebar.css" %}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<title>Add Item</title>
</head>
<body>
<h3>Contact Form</h3>
<hr/>
<form method="post" action="/contact-form">
{% if messages %}
{% for msg in messages %}
<p>{{msg}}</p>
{% endfor %}
{% endif %}
{% csrf_token %}
<table border="1" cellpadding="5">
<tr>
<th>Product Name</th>
<td><input type="text" name="product_name" /></td>
</tr>
<tr>
<th>Product Category</th>
<td><input type="email" name="product_category" /></td>
</tr>
<tr>
<th>Product Description</th>
<td>
<textarea name="product_description"></textarea>
</td>
</tr>
<tr>
<th>To Buy</th>
<td>
<input type="checkbox" name="to_buy">
</td>
</tr>
<tr>
<th>Icon</th>
<td>
<input type="file" id = "iconFile" name="icon">
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
<div class = "listViewHeader">
<div class = "breadcrumbsHead">
BREADCRUMBS
</div>
</div>
<div class = "lowerPage">
<div class = "sidebar">
<div class = "sideItem text fridge">
FRIDGE
</div>
<div class = "sideItem icon fridge">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text recipes">
RECIPES
</div>
<div class = "sideItem icon recipes">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text stats">
STATS
</div>
<div class = "sideItem icon stats">
<div class = "circle"> :3 </div>
</div>
<div class = "sideItem text toBuy">
TO BUY
</div>
<div class = "sideItem icon toBuy">
<div class = "circle"> :3 </div>
</div>
</div>
</div>
<h3>Add Item</h3>
<form method="POST" enctype="multipart/form-data" div class="main">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
<a href="http://127.0.0.1:8000/fridge/list" div class="main">Back</a>
</body>
</html>
\ No newline at end of file
......@@ -47,9 +47,9 @@
</div>
<h2>Fridge</h2>
<table style="width:70%" div class="main">
<tr><th colspan="5"><a href="http://127.0.0.1:8000/fridge/add/"> Add Item</a></th></tr>
<tr><th></th>
<th><a href="http://127.0.0.1:8000/fridge{{object_list.Product_ID}}">Name</a></th>
<tr><th colspan="5"><a href="{{request.path}}add"> Add Item</a></th></tr>
<tr>
<th><a href="http://127.0.0.1:8000/fridge/{{object_list.Product_ID}}">Name</a></th>
<th><a href="http://127.0.0.1:8000/fridge/{{object_list.Product_ID}}">Description</a></th>
<th>Quantity</th>
<th>Expiration Date</th>
......
......@@ -4,7 +4,7 @@ from django.conf.urls.static import static
from django.views.generic import TemplateView
from django.urls import include, path
from Breadcrumbs import views
from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type, ItemViewPDate#item_view_by_pdate
from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type, ItemViewPDate, add_item
urlpatterns = [
url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
......@@ -13,8 +13,9 @@ urlpatterns = [
#url('', ProductListView.as_view(), name='home'),
path('fridge/add/', add_product_type, name = 'product-type-form'),
#path('fridge/<pk>/delete', ProductTypeDeleteView.as_view()),
path('fridge/<id>/delete', delete_product_type, name='product-type-delete'),
url(r'^fridge/(?P<Product_ID>\d+)/$', ItemViewPDate.as_view(), name='item-purchase-date-view' )
path('fridge/<id>/delete', delete_product_type, name='product-type-delete'),
url(r'^fridge/(?P<Product_ID>\d+)/$', ItemViewPDate.as_view(), name='item-purchase-date-view'),
path('fridge/<id>/add/', add_item, name = 'add-item'),
]
if settings.DEBUG:
......
......@@ -100,4 +100,26 @@ class ItemViewPDate(ListView):
#def item_view_by_pdate(request, Product_ID):
# items = Item.objects.filter(User_ID = self.request.user).filter(Product_ID= Product_ID)
# context = items
# return render(request,'placeholder-items.html',items)
\ No newline at end of file
# return render(request,'placeholder-items.html',items)
def add_item(request, id):
context = {}
if request.method == 'POST':
form = AddItemForm(request.POST, request.FILES)
if form.is_valid():
#the name in quotation marks should match the name in the form
item_qty = form.cleaned_data.get("Item_Quantity")
qty_unit = form.cleaned_data.get("Quantity_Unit")
item_description = form.cleaned_data.get("Item_Description")
purchase_date = form.cleaned_data.get("Purchase_Date")
exp_date = form.cleaned_data.get("Expiration_Date")
is_consumed = form.cleaned_data.get("Is_Consumed")
product_type = id
#equating the variables you just declared with the object youre creating
instance = Item.objects.create(Item_Quantity = item_qty, Quantity_Unit = qty_unit, Item_Description = item_description, Purchase_Date = purchase_date, Expiration_Date = exp_date, Is_Consumed = is_consumed, Product_ID = product_type)
instance.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
else:
form = ProductTypeForm()
context['form'] = form
return render(request,'add-product-type.html',context)
\ No newline at end of file
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