Skip to content

Commit 614c440

Browse files
Matthew HolmesMatthew Holmes
authored andcommitted
adding grocery list Lab review
1 parent 9ef70e5 commit 614c440

File tree

25 files changed

+518
-21
lines changed

25 files changed

+518
-21
lines changed

Code/matthew/django/labs/03_grocery_list/grocery_list/grocery_app/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class List(models.Model):
99
delete= models.BooleanField(default=False)
1010

1111
def __str__(self):
12-
return f'{self.new}: {self.date}'
12+
return f'{self.new}: {self.date}'
13+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "grocery_app/index.html" %}
2+
{% load static %}
3+
<body>
4+
{% block content %}
5+
<h1>Edit</h1>
6+
{{item}}
7+
{% endblock content %}
8+
</body>
9+
</html>
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
<!DOCTYPE html>
2+
{% load static %}
23
<html lang="en">
34
<head>
45
<meta charset="UTF-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
67
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<!-- static -->
9+
<link rel="stylesheet" href="{% static 'css/style.css' %}">
710
<title>Grocery List</title>
811
</head>
912
<body>
13+
{% block content %}
14+
1015
<h1>Home</h1>
11-
1216
<form action="{% url 'save' %}" method="POST">
1317
{% csrf_token %}
1418
{{new_item}}
1519
<button type="submit">Submit</button>
1620
</form>
17-
21+
1822
{% for item in show_items %}
19-
23+
2024
<ul>
21-
22-
<form action="{% url 'delete' item.id %}" method="GET">
23-
<label for="del">{{item}}</label>
24-
<input type="checkbox" name="del" id="del">
25-
<button type="submit" name="del">Delete</button>
26-
</form>
25+
{{item}}
26+
<a href="{% url 'edit' item.id %}">Edit</a>
27+
<a href="{% url 'delete' item.id %}">Delete</a>
2728
</ul>
28-
29+
2930
{% endfor %}
30-
31+
32+
33+
{% endblock content %}
3134
</body>
32-
</html>
35+
</html>
36+
37+
38+
39+
40+
41+
{% comment %} <form action="{% url 'delete' item.id %}" method="GET">
42+
<label for="del">{{item}}</label>
43+
<input type="checkbox" name="del" id="del">
44+
<button type="submit" name="del">Delete</button>
45+
</form> {% endcomment %}

Code/matthew/django/labs/03_grocery_list/grocery_list/grocery_app/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
path('home/', views.home, name='home'),
2323
path('save/', views.save, name='save'),
2424
path('delete/<int:id>/', views.delete, name='delete'),
25+
path('edit/<int:id>/', views.edit, name='edit')
2526
]

Code/matthew/django/labs/03_grocery_list/grocery_list/grocery_app/views.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@ def home(request):
1818

1919
return render(request, 'grocery_app/index.html', context)
2020

21+
# add new item. Must be logged into a user
2122
def save(request):
2223
if request.method == "POST":
2324
form= NewItem(request.POST)
2425
if form.is_valid():
2526
text= form.cleaned_data['item']
26-
user= request.user
2727
#
2828
list=List()
2929
list.new= text
30-
list.user= user
30+
list.user= request.user
3131
list.save()
3232
return HttpResponseRedirect(reverse('home'))
3333

3434
def delete(request, id):
35-
if request.method == 'GET':
36-
List.objects.filter(id=id).delete()
37-
# list= get_object_or_404(List, id=id)
38-
# list.delete
35+
List.objects.filter(id=id).delete()
36+
37+
3938
return HttpResponseRedirect(reverse('home'))
4039

41-
40+
def edit(request, id):
41+
item= List.objects.filter(id=id)
42+
43+
context= {
44+
'item': item,
45+
}
46+
47+
return render(request, 'grocery_app/edit.html', context)

Code/matthew/django/labs/03_grocery_list/grocery_list/grocery_proj/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
# Static files (CSS, JavaScript, Images)
118118
# https://docs.djangoproject.com/en/4.0/howto/static-files/
119119

120-
STATIC_URL = 'static/'
120+
STATIC_URL = '/static/'
121+
STATICFILES_DIRS= [str(BASE_DIR.joinpath('static'))]
121122

122123
# Default primary key field type
123124
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: aqua;
3+
}

Code/matthew/django/labs/03_grocery_list/review/grocery_app/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
from .models import *
3+
# Register your models here.
4+
5+
admin.site.register(Department)
6+
admin.site.register(GroceryItem)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class GroceryAppConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'grocery_app'

0 commit comments

Comments
 (0)