From 9cf3bd14b4d0de46af7026e51c26bf951fbc3672 Mon Sep 17 00:00:00 2001 From: thepjos Date: Mon, 13 Mar 2023 09:46:00 -0500 Subject: [PATCH 1/5] imported messages, adding code to delete button --- main_app/includes/messages.html | 7 ++++++ main_app/templates/kids/detail.html | 38 +++++++++-------------------- main_app/urls.py | 1 + main_app/views.py | 11 +++++++++ 4 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 main_app/includes/messages.html diff --git a/main_app/includes/messages.html b/main_app/includes/messages.html new file mode 100644 index 0000000..0b9ee4f --- /dev/null +++ b/main_app/includes/messages.html @@ -0,0 +1,7 @@ +{% if messages %} + +{% endif %} \ No newline at end of file diff --git a/main_app/templates/kids/detail.html b/main_app/templates/kids/detail.html index 99e2139..677b903 100644 --- a/main_app/templates/kids/detail.html +++ b/main_app/templates/kids/detail.html @@ -1,6 +1,7 @@ {% extends 'base.html' %} {% block content %} +
{{ kid.name }} Details
@@ -58,14 +59,20 @@

{{ kid.name }}'s Chores

- + {{ kid.name}} did - {{ chore.name }} on - {{ chore.date }} for + "{{ chore.name }}" for {{ chore.amount }} dollars - + +
+
+ {% csrf_token %} + + +
+
{% endfor %} @@ -92,7 +99,6 @@

Available Chores

{{ chore.name }}
- {{ chore.date }}
{{ chore.description }}
{{ chore.amount }}
@@ -109,29 +115,7 @@

Available Chores

{{kid.name}} Already Has All Chores Available
{% endif %}
-
diff --git a/main_app/urls.py b/main_app/urls.py index c22265a..1fa180a 100644 --- a/main_app/urls.py +++ b/main_app/urls.py @@ -14,6 +14,7 @@ path('parents//add_kid/', views.add_kid, name='add_kid'), path('kids//assoc_chore//', views.assoc_chore, name='assoc_chore'), + path('kids//assoc_chore//', views.delete_chore, name='delete_chore'), # add photo path('kids//add_photo/', views.add_photo, name='add_photo'), diff --git a/main_app/views.py b/main_app/views.py index a4f1653..c648807 100644 --- a/main_app/views.py +++ b/main_app/views.py @@ -7,6 +7,7 @@ from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib import messages import uuid import boto3 @@ -79,6 +80,14 @@ def assoc_chore(request, kid_id, chore_id): return redirect('kids_detail', kid_id=kid_id) +@login_required +def delete_chore(request, kid_id, chore_id): + # Note that you can pass a toy's id instead of the whole toy object + Kid.objects.get(id=kid_id).chores.remove(chore_id) + messages.success(request, "SUCCESS YES") + return redirect('kids_detail', kid_id=kid_id) + + # Add the chores index view @login_required def chores_index(request): @@ -158,6 +167,7 @@ class ChoreUpdate(LoginRequiredMixin, UpdateView): class ChoreDelete(LoginRequiredMixin, DeleteView): model = Chore success_url = '/chores' + # messages.success("SUCCESS YES") @login_required def add_photo(request, kid_id): @@ -175,6 +185,7 @@ def add_photo(request, kid_id): return redirect('kids_detail', kid_id=kid_id) return redirect('kids_detail', kid_id=kid_id) + def signup(request): error_message = '' if request.method == 'POST': From e0193241804db74912bf00159025e3f5f0d8e901 Mon Sep 17 00:00:00 2001 From: thepjos Date: Mon, 13 Mar 2023 10:06:17 -0500 Subject: [PATCH 2/5] got delete to render but no message --- main_app/templates/kids/detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_app/templates/kids/detail.html b/main_app/templates/kids/detail.html index 677b903..da00c0e 100644 --- a/main_app/templates/kids/detail.html +++ b/main_app/templates/kids/detail.html @@ -67,7 +67,7 @@

{{ kid.name }}'s Chores

-
+ {% csrf_token %} From 4a59cd7784e2c52a97c532e025e7a3bd36182d72 Mon Sep 17 00:00:00 2001 From: thepjos Date: Tue, 14 Mar 2023 09:28:27 -0500 Subject: [PATCH 3/5] messages almost working --- main_app/templates/base.html | 6 +++++- main_app/{includes => templates}/messages.html | 5 ++++- main_app/urls.py | 2 +- main_app/views.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) rename main_app/{includes => templates}/messages.html (92%) diff --git a/main_app/templates/base.html b/main_app/templates/base.html index 6a48d33..5bc8a56 100644 --- a/main_app/templates/base.html +++ b/main_app/templates/base.html @@ -39,7 +39,11 @@
-
+ +
+ + {% include 'messages.html' %} + {% block content %} {% endblock %}
diff --git a/main_app/includes/messages.html b/main_app/templates/messages.html similarity index 92% rename from main_app/includes/messages.html rename to main_app/templates/messages.html index 0b9ee4f..64fb495 100644 --- a/main_app/includes/messages.html +++ b/main_app/templates/messages.html @@ -1,7 +1,10 @@ + + {% if messages %}
    {% for message in messages %}
  • {{ message }}
  • {% endfor %}
-{% endif %} \ No newline at end of file +{% endif %} + diff --git a/main_app/urls.py b/main_app/urls.py index 1fa180a..9298a23 100644 --- a/main_app/urls.py +++ b/main_app/urls.py @@ -14,7 +14,7 @@ path('parents//add_kid/', views.add_kid, name='add_kid'), path('kids//assoc_chore//', views.assoc_chore, name='assoc_chore'), - path('kids//assoc_chore//', views.delete_chore, name='delete_chore'), + path('kids//unassoc_chore//', views.delete_chore, name='delete_chore'), # add photo path('kids//add_photo/', views.add_photo, name='add_photo'), diff --git a/main_app/views.py b/main_app/views.py index c648807..92b03e4 100644 --- a/main_app/views.py +++ b/main_app/views.py @@ -84,8 +84,8 @@ def assoc_chore(request, kid_id, chore_id): def delete_chore(request, kid_id, chore_id): # Note that you can pass a toy's id instead of the whole toy object Kid.objects.get(id=kid_id).chores.remove(chore_id) - messages.success(request, "SUCCESS YES") return redirect('kids_detail', kid_id=kid_id) + messages.success(request, "SUCCESS YES") # Add the chores index view From 40ec5d21179f044673368f976452b7096154f564 Mon Sep 17 00:00:00 2001 From: thepjos Date: Tue, 14 Mar 2023 10:12:59 -0500 Subject: [PATCH 4/5] can add AN amount to balance --- main_app/models.py | 6 ++++++ main_app/views.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main_app/models.py b/main_app/models.py index 9e87425..2d54628 100644 --- a/main_app/models.py +++ b/main_app/models.py @@ -2,6 +2,7 @@ from django.urls import reverse from django import forms from django.contrib.auth.models import User +from django.db.models import F @@ -55,6 +56,11 @@ def __str__(self): def get_absolute_url(self): return reverse('kids_detail', kwargs={'kid_id': self.id}) + + # func for piggy bank increase + def add_to_balance(self): + self.current_balance += 25 + self.save() class Photo(models.Model): diff --git a/main_app/views.py b/main_app/views.py index 92b03e4..32bd5d5 100644 --- a/main_app/views.py +++ b/main_app/views.py @@ -71,7 +71,13 @@ def kids_detail(request, kid_id): chores_kid_hasnt_done = Chore.objects.exclude(id__in=id_list) - return render(request, 'kids/detail.html', { 'kid': kid, 'chores': chores_kid_hasnt_done }) + # updated_balance = Kid.objects.get(id=kid_id).add_to_balance() + + return render(request, 'kids/detail.html', { + 'kid': kid, + 'chores': chores_kid_hasnt_done, + # 'current_balance': updated_balance + }) @login_required def assoc_chore(request, kid_id, chore_id): @@ -84,6 +90,7 @@ def assoc_chore(request, kid_id, chore_id): def delete_chore(request, kid_id, chore_id): # Note that you can pass a toy's id instead of the whole toy object Kid.objects.get(id=kid_id).chores.remove(chore_id) + Kid.objects.get(id=kid_id).add_to_balance() return redirect('kids_detail', kid_id=kid_id) messages.success(request, "SUCCESS YES") From 63daab107af48a68ddc659c7ca2b94c9b100064c Mon Sep 17 00:00:00 2001 From: thepjos Date: Tue, 14 Mar 2023 10:28:53 -0500 Subject: [PATCH 5/5] got bank to update with chore amount --- main_app/models.py | 4 ++-- main_app/templates/kids/detail.html | 2 +- main_app/urls.py | 2 +- main_app/views.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main_app/models.py b/main_app/models.py index 2d54628..cdf5613 100644 --- a/main_app/models.py +++ b/main_app/models.py @@ -58,8 +58,8 @@ def get_absolute_url(self): return reverse('kids_detail', kwargs={'kid_id': self.id}) # func for piggy bank increase - def add_to_balance(self): - self.current_balance += 25 + def add_to_balance(self, amt): + self.current_balance += amt self.save() diff --git a/main_app/templates/kids/detail.html b/main_app/templates/kids/detail.html index da00c0e..0e263c9 100644 --- a/main_app/templates/kids/detail.html +++ b/main_app/templates/kids/detail.html @@ -67,7 +67,7 @@

{{ kid.name }}'s Chores

- + {% csrf_token %} diff --git a/main_app/urls.py b/main_app/urls.py index 9298a23..9781ec7 100644 --- a/main_app/urls.py +++ b/main_app/urls.py @@ -14,7 +14,7 @@ path('parents//add_kid/', views.add_kid, name='add_kid'), path('kids//assoc_chore//', views.assoc_chore, name='assoc_chore'), - path('kids//unassoc_chore//', views.delete_chore, name='delete_chore'), + path('kids//unassoc_chore///', views.delete_chore, name='delete_chore'), # add photo path('kids//add_photo/', views.add_photo, name='add_photo'), diff --git a/main_app/views.py b/main_app/views.py index 32bd5d5..a75239c 100644 --- a/main_app/views.py +++ b/main_app/views.py @@ -87,10 +87,10 @@ def assoc_chore(request, kid_id, chore_id): @login_required -def delete_chore(request, kid_id, chore_id): +def delete_chore(request, kid_id, chore_id, chore_amount): # Note that you can pass a toy's id instead of the whole toy object Kid.objects.get(id=kid_id).chores.remove(chore_id) - Kid.objects.get(id=kid_id).add_to_balance() + Kid.objects.get(id=kid_id).add_to_balance(chore_amount) return redirect('kids_detail', kid_id=kid_id) messages.success(request, "SUCCESS YES")