Commit 41400cd4 authored by Julia Santos's avatar Julia Santos

Added different sorting views for Product Type, added option to delete items

parent 4af4656a
<!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>Add Product Type</title> <title>Add Product Type</title>
</head> </head>
<body> <body>
<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 Product Type</h3> <h3>Add Product Type</h3>
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" div class="main">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Submit"> <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
...@@ -46,8 +46,16 @@ ...@@ -46,8 +46,16 @@
</div> </div>
</div> </div>
<h2>Fridge</h2> <h2>Fridge</h2>
<table style="width:70%" div class="main"> <table style="width:70%" div class="main">
<tr><th></th><th>name</th><th>category</th><th>description</th><th>to buy?</th><th>user</th></tr> <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/list/">name</a></th>
<th><a href="http://127.0.0.1:8000/fridge/list-category">category</a></th>
<th>description</th>
<th>to buy?</th>
<th>user</th>
</tr>
{% for product in object_list %} {% for product in object_list %}
<tr> <tr>
<th> <th>
...@@ -66,7 +74,7 @@ ...@@ -66,7 +74,7 @@
{{product.To_Buy}} {{product.To_Buy}}
</th> </th>
<th> <th>
{{product.User_ID.username}} <a href='http://127.0.0.1:8000/fridge/{{product.Product_ID}}/delete'>Delete?</a>
</th> </th>
</tr> </tr>
{% endfor %} {% endfor %}
......
<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm">
</form>
<html>
<body>
<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm">
</form>
</body>
</html>
<h2>Log In</h2> {% load static %}
<link rel="stylesheet" href="{%static "sidebar.css" %}">
<div class = "listViewHeader">
<div class = "breadcrumbsHead">
BREADCRUMBS
</div>
</div>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
......
...@@ -4,13 +4,16 @@ from django.conf.urls.static import static ...@@ -4,13 +4,16 @@ 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 ProductListView, add_product_type from .views import ProductListViewName, ProductListViewCategory, add_product_type, delete_product_type #ProductTypeDeleteView
urlpatterns = [ urlpatterns = [
url(r'^fridge/list/', ProductListView.as_view(), name='fridgeL'), url(r'^fridge/list/', ProductListViewName.as_view(), name='fridgeLN'),
url(r'^fridge/list-category', ProductListViewCategory.as_view(), name='fridgeLC'),
url('accounts/', include('django.contrib.auth.urls')), url('accounts/', include('django.contrib.auth.urls')),
#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/<id>/delete', delete_product_type, name='product-type-delete'),
] ]
if settings.DEBUG: if settings.DEBUG:
......
from django.views.generic import ListView from django.views.generic import ListView
from .models import User, Product_Type, Item, Recipe
from django.db.models import Q from django.db.models import Q
from .forms import LoginForm, ProductTypeForm from .forms import LoginForm, ProductTypeForm
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render from django.shortcuts import render, get_object_or_404
from django.views.generic.edit import DeleteView
from .models import User, Product_Type, Item, Recipe
#class UserListView(ListView): #class UserListView(ListView):
# model = User # model = User
...@@ -12,7 +15,7 @@ from django.shortcuts import render ...@@ -12,7 +15,7 @@ from django.shortcuts import render
# def get_queryset(self): # def get_queryset(self):
# return User.objects.all().order_by('User_ID') # return User.objects.all().order_by('User_ID')
#User = settings.AUTH_USER_MODEL #User = settings.AUTH_USER_MODEL
class ProductListView(ListView): class ProductListViewName(ListView):
model = Product_Type model = Product_Type
template_name = 'placeholder-list.html' template_name = 'placeholder-list.html'
context_object_name = 'product' context_object_name = 'product'
...@@ -20,6 +23,15 @@ class ProductListView(ListView): ...@@ -20,6 +23,15 @@ class ProductListView(ListView):
def get_queryset(self): def get_queryset(self):
return Product_Type.objects.filter(User_ID=self.request.user).order_by('Product_Name') return Product_Type.objects.filter(User_ID=self.request.user).order_by('Product_Name')
class ProductListViewCategory(ListView):
model = Product_Type
template_name = 'placeholder-list.html'
context_object_name = 'product'
def get_queryset(self):
return Product_Type.objects.filter(User_ID=self.request.user).order_by('Product_Category')
def login(request): def login(request):
username = "not logged in" username = "not logged in"
...@@ -28,7 +40,7 @@ def login(request): ...@@ -28,7 +40,7 @@ def login(request):
if MyLoginForm.is_valid(): if MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username'] username = MyLoginForm.cleaned_data['username']
return HttpResponseRedirect('/fridge/list') #return HttpResponseRedirect('/fridge/list')
else: else:
MyLoginForm = Loginform() MyLoginForm = Loginform()
...@@ -54,3 +66,23 @@ def add_product_type(request): ...@@ -54,3 +66,23 @@ def add_product_type(request):
context['form'] = form context['form'] = form
return render(request,'add-product-type.html',context) return render(request,'add-product-type.html',context)
def delete_product_type(request,id):
context = {}
obj = get_object_or_404(Product_Type,Product_ID = id)
if request.method=="POST":
obj.delete()
return HttpResponseRedirect("/fridge/list/")
return render(request, 'product-type-confirm-delete.html',context)
# class ProductTypeDeleteView(DeleteView):
# models = Product_Type
# template_name = 'product-type-confirm-delete.html'
# success_url = 'fridge/list/'
# def get_object(self, queryset=None):
# obj = super(ProductTypeDeleteView, self).get_object()
# if not obj.owner == self.request.user:
# raise Http404
# return obj
\ No newline at end of file
...@@ -130,4 +130,4 @@ MEDIA_URL = '/media/' ...@@ -130,4 +130,4 @@ MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#for login #for login
#LOGIN_REDIRECT_uRL = '/' LOGIN_REDIRECT_URL = '/fridge/list/'
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