Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Hunger Buster - Breadcrumbs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julia Santos
Hunger Buster - Breadcrumbs
Commits
e4fc58d5
Commit
e4fc58d5
authored
Mar 17, 2021
by
Julia Santos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to allow users to add items
parent
ad9dcc73
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
50 deletions
+89
-50
.gitignore
.gitignore
+2
-1
forms.py
Breadcrumbs/forms.py
+11
-1
add-item.html
Breadcrumbs/templates/add-item.html
+46
-41
placeholder-items.html
Breadcrumbs/templates/placeholder-items.html
+3
-3
urls.py
Breadcrumbs/urls.py
+4
-3
views.py
Breadcrumbs/views.py
+23
-1
No files found.
.gitignore
View file @
e4fc58d5
...
@@ -2,3 +2,4 @@ myenv/
...
@@ -2,3 +2,4 @@ myenv/
*.pyc
*.pyc
db.sqlite3
db.sqlite3
__pycache__
__pycache__
media/upload/
\ No newline at end of file
Breadcrumbs/forms.py
View file @
e4fc58d5
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
):
...
@@ -11,3 +12,12 @@ class ProductTypeForm(forms.Form):
...
@@ -11,3 +12,12 @@ class ProductTypeForm(forms.Form):
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'
]
)
])
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
)
Breadcrumbs/templates/add-item.html
View file @
e4fc58d5
<!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 For
m
</title>
<title>
Add Ite
m
</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"
>
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 %}
{% csrf_token %}
<table
border=
"1"
cellpadding=
"5"
>
{{ form.as_p }}
<tr>
<input
type=
"submit"
value=
"Submit"
>
<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>
</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
Breadcrumbs/templates/placeholder-items.html
View file @
e4fc58d5
...
@@ -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>
...
...
Breadcrumbs/urls.py
View file @
e4fc58d5
...
@@ -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'
),
...
@@ -14,7 +14,8 @@ urlpatterns = [
...
@@ -14,7 +14,8 @@ urlpatterns = [
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
:
...
...
Breadcrumbs/views.py
View file @
e4fc58d5
...
@@ -101,3 +101,25 @@ class ItemViewPDate(ListView):
...
@@ -101,3 +101,25 @@ class ItemViewPDate(ListView):
# 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)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment