質問編集履歴
5
不要な個所の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,12 +4,9 @@
|
|
4
4
|
|
5
5
|
サイトのページネーションの手順通りにコードを打ち込み
|
6
6
|
django のページネーションを試みたのですが、上手くWebページ上に表示されず、空白のままになってしまっています。
|
7
|
-
どうすれば、ページ
|
7
|
+
どうすれば、ページネーションを上手く動作させられるのかお教えいただけますと幸いです。
|
8
8
|
|
9
9
|
ご教授いただけますと幸いです。
|
10
|
-
|
11
|
-
また、もしよろしければ、
|
12
|
-
以下の一番下のkakeibo.pyファイル内で何がどのように行われているかが、よく分からないため、その点に関してもお教えいただけますと幸いです。
|
13
10
|
|
14
11
|
よろしくお願いいたします。
|
15
12
|
|
@@ -37,44 +34,7 @@
|
|
37
34
|
├── urls.py
|
38
35
|
└── views.py
|
39
36
|
|
40
|
-
|
41
|
-
```kakeibo/models.py
|
42
|
-
from django.db import models
|
43
|
-
|
44
|
-
# Create your models here.
|
45
|
-
|
46
|
-
|
47
|
-
#カテゴリ名を保存するためのモデル
|
48
|
-
class PaymentCategory(models.Model):
|
49
|
-
name = models.CharField("カテゴリ名", max_length=32)
|
50
|
-
|
51
|
-
def __str__(self):
|
52
|
-
return self.name
|
53
|
-
|
54
|
-
class Payment(models.Model):
|
55
|
-
date = models.DateField("日付")
|
56
|
-
price = models.IntegerField("金額")
|
57
|
-
category = models.ForeignKey(PaymentCategory,
|
58
|
-
on_delete=models.PROTECT,
|
59
|
-
verbose_name="カテゴリ")
|
60
|
-
description = models.TextField('摘要', null=True, blank=True)
|
61
|
-
|
62
|
-
|
63
|
-
```
|
64
|
-
```kakeibo/urls.py
|
65
|
-
from django.urls import path, include
|
66
|
-
from . import views
|
67
|
-
|
68
|
-
app_name = "kakeibo"
|
69
|
-
|
70
|
-
urlpatterns = [
|
71
|
-
path('', views.PaymentList.as_view(), name="payment_list"),
|
72
|
-
]
|
73
|
-
|
74
|
-
```
|
75
|
-
|
76
37
|
```kakeibo/views.py
|
77
|
-
|
78
38
|
from django.views.generic import ListView
|
79
39
|
from django.shortcuts import render
|
80
40
|
from .models import Payment
|
@@ -100,8 +60,29 @@
|
|
100
60
|
return context
|
101
61
|
```
|
102
62
|
|
63
|
+
```kakeibo/models.py
|
64
|
+
from django.db import models
|
65
|
+
|
66
|
+
# Create your models here.
|
67
|
+
|
68
|
+
|
69
|
+
#カテゴリ名を保存するためのモデル
|
70
|
+
class PaymentCategory(models.Model):
|
71
|
+
name = models.CharField("カテゴリ名", max_length=32)
|
72
|
+
|
73
|
+
def __str__(self):
|
74
|
+
return self.name
|
75
|
+
|
76
|
+
class Payment(models.Model):
|
77
|
+
date = models.DateField("日付")
|
78
|
+
price = models.IntegerField("金額")
|
79
|
+
category = models.ForeignKey(PaymentCategory,
|
80
|
+
on_delete=models.PROTECT,
|
81
|
+
verbose_name="カテゴリ")
|
82
|
+
description = models.TextField('摘要', null=True, blank=True)
|
83
|
+
```
|
84
|
+
|
103
85
|
```kakeibo/templates/kakeibo/payment_list.html
|
104
|
-
|
105
86
|
{% extends "kakeibo/base.html" %}
|
106
87
|
{% load humanize %}
|
107
88
|
{% load kakeibo %}
|
4
不必要な情報の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,14 +17,6 @@
|
|
17
17
|
kakeibo
|
18
18
|
├── __init__.py
|
19
19
|
├── __pycache__
|
20
|
-
│ ├── __init__.cpython-38.pyc
|
21
|
-
│ ├── admin.cpython-38.pyc
|
22
|
-
│ ├── apps.cpython-38.pyc
|
23
|
-
│ ├── forms.cpython-38.pyc
|
24
|
-
│ ├── models.cpython-38.pyc
|
25
|
-
│ ├── urls.cpython-38.pyc
|
26
|
-
│ ├── views.cpython-38.pyc
|
27
|
-
│ └── widgets.cpython-38.pyc
|
28
20
|
├── admin.py
|
29
21
|
├── apps.py
|
30
22
|
├── forms.py
|
@@ -32,21 +24,14 @@
|
|
32
24
|
│ ├── 0001_initial.py
|
33
25
|
│ ├── __init__.py
|
34
26
|
│ └── __pycache__
|
35
|
-
│ ├── 0001_initial.cpython-38.pyc
|
36
|
-
│ └── __init__.cpython-38.pyc
|
37
27
|
├── models.py
|
38
28
|
├── static
|
39
|
-
│ └── kakeibo
|
40
|
-
│ └── css
|
41
|
-
│ ├── reset.css
|
42
|
-
│ └── style.css
|
43
29
|
├── templates
|
44
30
|
│ └── kakeibo
|
45
31
|
│ ├── base.html
|
46
32
|
│ └── payment_list.html
|
47
33
|
├── templatetags
|
48
34
|
│ ├── __pycache__
|
49
|
-
│ │ └── kakeibo.cpython-38.pyc
|
50
35
|
│ └── kakeibo.py
|
51
36
|
├── tests.py
|
52
37
|
├── urls.py
|
3
不必要な部分の消去
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,6 @@
|
|
14
14
|
よろしくお願いいたします。
|
15
15
|
|
16
16
|
以下に、現在のアプリのディレクトリ構造とコードを記載しておきます。
|
17
|
-
```
|
18
17
|
kakeibo
|
19
18
|
├── __init__.py
|
20
19
|
├── __pycache__
|
@@ -52,7 +51,7 @@
|
|
52
51
|
├── tests.py
|
53
52
|
├── urls.py
|
54
53
|
└── views.py
|
55
|
-
|
54
|
+
|
56
55
|
|
57
56
|
```kakeibo/models.py
|
58
57
|
from django.db import models
|
@@ -64,10 +63,8 @@
|
|
64
63
|
class PaymentCategory(models.Model):
|
65
64
|
name = models.CharField("カテゴリ名", max_length=32)
|
66
65
|
|
67
|
-
#カテゴリ名を入力されたものをそのまま返すようにしている。
|
68
66
|
def __str__(self):
|
69
|
-
|
67
|
+
return self.name
|
70
|
-
|
71
68
|
|
72
69
|
class Payment(models.Model):
|
73
70
|
date = models.DateField("日付")
|
@@ -77,22 +74,6 @@
|
|
77
74
|
verbose_name="カテゴリ")
|
78
75
|
description = models.TextField('摘要', null=True, blank=True)
|
79
76
|
|
80
|
-
|
81
|
-
#以下、Incomeにおいても同じコード。
|
82
|
-
class IncomeCategory(models.Model):
|
83
|
-
name = models.CharField('カテゴリ名', max_length=32)
|
84
|
-
|
85
|
-
def __str__(self):
|
86
|
-
return self.name
|
87
|
-
|
88
|
-
|
89
|
-
class Income(models.Model):
|
90
|
-
date = models.DateField('日付')
|
91
|
-
price = models.IntegerField('金額')
|
92
|
-
category = models.ForeignKey(IncomeCategory,
|
93
|
-
on_delete=models.PROTECT,
|
94
|
-
verbose_name='カテゴリ')
|
95
|
-
description = models.TextField('摘要', null=True, blank=True)
|
96
77
|
|
97
78
|
```
|
98
79
|
```kakeibo/urls.py
|
@@ -107,12 +88,11 @@
|
|
107
88
|
|
108
89
|
```
|
109
90
|
|
110
|
-
|
111
91
|
```kakeibo/views.py
|
112
92
|
|
113
93
|
from django.views.generic import ListView
|
114
94
|
from django.shortcuts import render
|
115
|
-
from .models import Payment
|
95
|
+
from .models import Payment
|
116
96
|
from .forms import PaymentSearchForm
|
117
97
|
|
118
98
|
# Create your views here.
|
@@ -124,43 +104,7 @@
|
|
124
104
|
pagenate_by = 10
|
125
105
|
|
126
106
|
def get_queryset(self):
|
127
|
-
queryset = super().get_queryset()
|
128
|
-
self.form = form = PaymentSearchForm(self.request.GET or None)
|
129
|
-
|
130
|
-
if form.is_valid():
|
131
|
-
year = form.cleaned_data.get('year')
|
132
|
-
# 何も選択されていないときは0の文字列が入るため、除外
|
133
|
-
if year and year != '0':
|
134
|
-
queryset = queryset.filter(date__year=year)
|
135
|
-
|
136
|
-
month = form.cleaned_data.get('month')
|
137
|
-
# 何も選択されていないときは0の文字列が入るため、除外
|
138
|
-
if month and month != '0':
|
139
|
-
queryset = queryset.filter(date__month=month)
|
140
|
-
|
141
|
-
|
107
|
+
・・・
|
142
|
-
greater_than = form.cleaned_data.get('greater_than')
|
143
|
-
if greater_than:
|
144
|
-
queryset = queryset.filter(price__gte=greater_than)
|
145
|
-
|
146
|
-
# 〇〇円以下の絞り込み
|
147
|
-
less_than = form.cleaned_data.get('less_than')
|
148
|
-
if less_than:
|
149
|
-
queryset = queryset.filter(price__lte=less_than)
|
150
|
-
|
151
|
-
# キーワードの絞り込み
|
152
|
-
key_word = form.cleaned_data.get('key_word')
|
153
|
-
if key_word:
|
154
|
-
# 空欄で区切り、順番に絞る、and検索
|
155
|
-
if key_word:
|
156
|
-
for word in key_word.split():
|
157
|
-
queryset = queryset.filter(description__icontains=word)
|
158
|
-
|
159
|
-
# カテゴリでの絞り込み
|
160
|
-
category = form.cleaned_data.get('category')
|
161
|
-
if category:
|
162
|
-
queryset = queryset.filter(category=category)
|
163
|
-
|
164
108
|
return queryset
|
165
109
|
|
166
110
|
def get_context_data(self, **kwargs):
|
@@ -177,56 +121,6 @@
|
|
177
121
|
{% load humanize %}
|
178
122
|
{% load kakeibo %}
|
179
123
|
{% block content %}
|
180
|
-
|
181
|
-
<!--検索フォーム-->
|
182
|
-
<form class="mt-2" id="search-form" action="" method="GET">
|
183
|
-
<div>
|
184
|
-
<label class="label mr-4">年月</label>
|
185
|
-
{{ search_form.year }}
|
186
|
-
{{ search_form.month }}
|
187
|
-
</div>
|
188
|
-
<div class="mt-4">
|
189
|
-
<label class="label mr-4">金額</label>
|
190
|
-
{{ search_form.greater_than }}
|
191
|
-
<span class="ml-4 mr-4">~</span>
|
192
|
-
{{ search_form.less_than }}
|
193
|
-
</div>
|
194
|
-
<div class="mt-4">
|
195
|
-
{{ search_form.key_word }}
|
196
|
-
<button class="btn btn-info ml-4" type="submit">検索</button>
|
197
|
-
</div>
|
198
|
-
<div class="mt-2 inline">
|
199
|
-
{{ search_form.category }}
|
200
|
-
</div>
|
201
|
-
</form>
|
202
|
-
|
203
|
-
<!--追加 表示件数-->
|
204
|
-
<p class="search-result mt-3">{{ page_obj.paginator.count }}件の検索結果</p>
|
205
|
-
|
206
|
-
<table class="table mt-3">
|
207
|
-
<tr>
|
208
|
-
<th>日付</th>
|
209
|
-
<th>カテゴリ</th>
|
210
|
-
<th>金額</th>
|
211
|
-
<th>摘要</th>
|
212
|
-
</tr>
|
213
|
-
|
214
|
-
<!--urls.pyファイル内でname="payment_list"と
|
215
|
-
逆からの参照ができるようにしていたものをinに利用している-->
|
216
|
-
{% for payment in payment_list %}
|
217
|
-
|
218
|
-
<tr>
|
219
|
-
<td>{{ payment.date }}</td>
|
220
|
-
<td>{{ payment.category }}</td>
|
221
|
-
<td>{{ payment.price|intcomma}}</td>
|
222
|
-
<td>
|
223
|
-
{% if payment.description %}
|
224
|
-
{{ payment.description }}
|
225
|
-
{% endif %}
|
226
|
-
</td>
|
227
|
-
</tr>
|
228
|
-
{% endfor %}
|
229
|
-
</table>
|
230
124
|
|
231
125
|
<div class="mt-5">
|
232
126
|
<!--一つ前-->
|
@@ -255,7 +149,6 @@
|
|
255
149
|
|
256
150
|
register = Library()
|
257
151
|
|
258
|
-
|
259
152
|
@register.simple_tag
|
260
153
|
def url_replace(request, field, value):
|
261
154
|
url_dict = request.GET.copy()
|
2
リンクの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
こちらの
|
2
|
+
|
2
|
-
https://qlitre-weblog.com/django-kakeibo-search-pagination/
|
3
|
+
https://qlitre-weblog.com/django-kakeibo-search-pagination/
|
4
|
+
|
5
|
+
サイトのページネーションの手順通りにコードを打ち込み
|
3
6
|
django のページネーションを試みたのですが、上手くWebページ上に表示されず、空白のままになってしまっています。
|
4
7
|
どうすれば、ページ数を表示できるのでしょうか?
|
5
8
|
|
1
参考にしたサイトの掲示をしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
+
こちらの
|
1
|
-
|
2
|
+
https://qlitre-weblog.com/django-kakeibo-search-pagination/サイトのページネーションの手順通りにコードを打ち込み
|
2
3
|
django のページネーションを試みたのですが、上手くWebページ上に表示されず、空白のままになってしまっています。
|
3
4
|
どうすれば、ページ数を表示できるのでしょうか?
|
4
5
|
|