Commit e4fc58d5 authored by Julia Santos's avatar Julia Santos

Trying to allow users to add items

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