質問編集履歴
2
modelを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -129,3 +129,157 @@
|
|
129
129
|
return render(request, 'mutual/index.html',{'propertys': propertys})
|
130
130
|
|
131
131
|
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
modelを修正
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
from django.db import models
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
class Property(models.Model):
|
144
|
+
|
145
|
+
title = models.CharField(max_length=50, blank=False)
|
146
|
+
|
147
|
+
comment = models.CharField(max_length=300, blank=False)
|
148
|
+
|
149
|
+
image = models.ImageField(upload_to = 'photos')
|
150
|
+
|
151
|
+
vacant_day_num = models.PositiveSmallIntegerField(blank=False)
|
152
|
+
|
153
|
+
place = models.CharField(max_length=50, blank=False)
|
154
|
+
|
155
|
+
price = models.PositiveSmallIntegerField(blank=False)
|
156
|
+
|
157
|
+
create_date = models.DateTimeField(auto_now=True)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
def get_vacant_day(self) -> str:
|
162
|
+
|
163
|
+
if self.vacant_day_num == 3:
|
164
|
+
|
165
|
+
return '月、火'
|
166
|
+
|
167
|
+
elif self.vacant_day_num == 96:
|
168
|
+
|
169
|
+
return '月、火、水、木、金、土、日'
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def __str__(self):
|
174
|
+
|
175
|
+
return self.title
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
viewを修正(コメントアウト)
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
def index(request):
|
184
|
+
|
185
|
+
propertys = Property.objects.all().order_by('-create_date')
|
186
|
+
|
187
|
+
logging.debug(property.vacant_day)
|
188
|
+
|
189
|
+
"""
|
190
|
+
|
191
|
+
for property in propertys:
|
192
|
+
|
193
|
+
setattr(property, 'vacant_day','')
|
194
|
+
|
195
|
+
if property.vacant_day_num == 3:
|
196
|
+
|
197
|
+
setattr(property, 'vacant_day','月、火')
|
198
|
+
|
199
|
+
property_list.append(property.vacant_day)
|
200
|
+
|
201
|
+
logging.debug(property.vacant_day)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
elif property.vacant_day_num == 96:
|
206
|
+
|
207
|
+
setattr(property, 'vacant_day','月、火、水、木、金、土、日')
|
208
|
+
|
209
|
+
property_list.append(property.vacant_day)
|
210
|
+
|
211
|
+
logging.debug(property.vacant_day)
|
212
|
+
|
213
|
+
"""
|
214
|
+
|
215
|
+
return render(request, 'mutual/index.html',{'propertys': propertys})
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
template
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
{% extends 'mutual/base.html' %}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
{% block content %}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
<h2>トップページ</h2>
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
{% for property in propertys %}
|
236
|
+
|
237
|
+
<table>
|
238
|
+
|
239
|
+
<tr>
|
240
|
+
|
241
|
+
<td rowspan="4"><img src="{{property.image.url}}" class="photo-img"></td>
|
242
|
+
|
243
|
+
<td>物件名</td>
|
244
|
+
|
245
|
+
<td>{{property.title}}</td>
|
246
|
+
|
247
|
+
<tr>
|
248
|
+
|
249
|
+
<td>曜日</td>
|
250
|
+
|
251
|
+
<td>{{property.vacantn_day}}</td>
|
252
|
+
|
253
|
+
</tr>
|
254
|
+
|
255
|
+
<tr>
|
256
|
+
|
257
|
+
<td>場所</td>
|
258
|
+
|
259
|
+
<td>{{property.place}}</td>
|
260
|
+
|
261
|
+
</tr>
|
262
|
+
|
263
|
+
<tr>
|
264
|
+
|
265
|
+
<td>金額</td>
|
266
|
+
|
267
|
+
<td>{{property.price}}</td>
|
268
|
+
|
269
|
+
</tr>
|
270
|
+
|
271
|
+
<tr>
|
272
|
+
|
273
|
+
<td colspan="3">{{property.comment}}</td>
|
274
|
+
|
275
|
+
</tr>
|
276
|
+
|
277
|
+
</table>
|
278
|
+
|
279
|
+
{% endfor %}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
{% endblock %}
|
284
|
+
|
285
|
+
```
|
1
コードを修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -95,3 +95,37 @@
|
|
95
95
|
どなたかご教授いただけると幸いです。
|
96
96
|
|
97
97
|
ご回答の程よろしくお願いいたします。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
修正後
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
def index(request):
|
106
|
+
|
107
|
+
propertys = Property.objects.all().order_by('-create_date')
|
108
|
+
|
109
|
+
for property in propertys:
|
110
|
+
|
111
|
+
if property.vacant_day_num == 3:
|
112
|
+
|
113
|
+
logging.debug('num is 3')
|
114
|
+
|
115
|
+
setattr(property, 'vacant_day','月、火')
|
116
|
+
|
117
|
+
logging.debug(property.vacant_day)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
elif property.vacant_day_num == 96:
|
122
|
+
|
123
|
+
logging.debug('num is 96')
|
124
|
+
|
125
|
+
setattr(property, 'vacant_day','月、火、水、木、金、土、日')
|
126
|
+
|
127
|
+
logging.debug(property.vacant_day)
|
128
|
+
|
129
|
+
return render(request, 'mutual/index.html',{'propertys': propertys})
|
130
|
+
|
131
|
+
```
|