File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from django .shortcuts import render
1+ from django .http import HttpResponse
2+ from account .models import Transaction
23
3- # Create your views here.
4+
5+ def current_balance_view (request ):
6+ balance = 0
7+ for transaction in Transaction .objects .all ():
8+ if transaction .type == Transaction .Type .INCOME :
9+ balance += transaction .amount
10+ else :
11+ balance -= transaction .amount
12+
13+ return HttpResponse (f"{ balance } บาท" )
Original file line number Diff line number Diff line change 1- """personal_finance URL Configuration
2-
3- The `urlpatterns` list routes URLs to views. For more information please see:
4- https://docs.djangoproject.com/en/3.1/topics/http/urls/
5- Examples:
6- Function views
7- 1. Add an import: from my_app import views
8- 2. Add a URL to urlpatterns: path('', views.home, name='home')
9- Class-based views
10- 1. Add an import: from other_app.views import Home
11- 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12- Including another URLconf
13- 1. Import the include() function: from django.urls import include, path
14- 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15- """
161from django .contrib import admin
172from django .urls import path
3+ from account .views import current_balance_view
184
195urlpatterns = [
206 path ('admin/' , admin .site .urls ),
7+ path ('account/current-balance/' , current_balance_view )
218]
You can’t perform that action at this time.
0 commit comments