質問編集履歴
2
modelを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -63,4 +63,81 @@
|
|
63
63
|
setattr(property, 'vacant_day','月、火、水、木、金、土、日')
|
64
64
|
logging.debug(property.vacant_day)
|
65
65
|
return render(request, 'mutual/index.html',{'propertys': propertys})
|
66
|
+
```
|
67
|
+
|
68
|
+
modelを修正
|
69
|
+
```
|
70
|
+
from django.db import models
|
71
|
+
|
72
|
+
class Property(models.Model):
|
73
|
+
title = models.CharField(max_length=50, blank=False)
|
74
|
+
comment = models.CharField(max_length=300, blank=False)
|
75
|
+
image = models.ImageField(upload_to = 'photos')
|
76
|
+
vacant_day_num = models.PositiveSmallIntegerField(blank=False)
|
77
|
+
place = models.CharField(max_length=50, blank=False)
|
78
|
+
price = models.PositiveSmallIntegerField(blank=False)
|
79
|
+
create_date = models.DateTimeField(auto_now=True)
|
80
|
+
|
81
|
+
def get_vacant_day(self) -> str:
|
82
|
+
if self.vacant_day_num == 3:
|
83
|
+
return '月、火'
|
84
|
+
elif self.vacant_day_num == 96:
|
85
|
+
return '月、火、水、木、金、土、日'
|
86
|
+
|
87
|
+
def __str__(self):
|
88
|
+
return self.title
|
89
|
+
```
|
90
|
+
viewを修正(コメントアウト)
|
91
|
+
```
|
92
|
+
def index(request):
|
93
|
+
propertys = Property.objects.all().order_by('-create_date')
|
94
|
+
logging.debug(property.vacant_day)
|
95
|
+
"""
|
96
|
+
for property in propertys:
|
97
|
+
setattr(property, 'vacant_day','')
|
98
|
+
if property.vacant_day_num == 3:
|
99
|
+
setattr(property, 'vacant_day','月、火')
|
100
|
+
property_list.append(property.vacant_day)
|
101
|
+
logging.debug(property.vacant_day)
|
102
|
+
|
103
|
+
elif property.vacant_day_num == 96:
|
104
|
+
setattr(property, 'vacant_day','月、火、水、木、金、土、日')
|
105
|
+
property_list.append(property.vacant_day)
|
106
|
+
logging.debug(property.vacant_day)
|
107
|
+
"""
|
108
|
+
return render(request, 'mutual/index.html',{'propertys': propertys})
|
109
|
+
```
|
110
|
+
template
|
111
|
+
```
|
112
|
+
{% extends 'mutual/base.html' %}
|
113
|
+
|
114
|
+
{% block content %}
|
115
|
+
|
116
|
+
<h2>トップページ</h2>
|
117
|
+
|
118
|
+
{% for property in propertys %}
|
119
|
+
<table>
|
120
|
+
<tr>
|
121
|
+
<td rowspan="4"><img src="{{property.image.url}}" class="photo-img"></td>
|
122
|
+
<td>物件名</td>
|
123
|
+
<td>{{property.title}}</td>
|
124
|
+
<tr>
|
125
|
+
<td>曜日</td>
|
126
|
+
<td>{{property.vacantn_day}}</td>
|
127
|
+
</tr>
|
128
|
+
<tr>
|
129
|
+
<td>場所</td>
|
130
|
+
<td>{{property.place}}</td>
|
131
|
+
</tr>
|
132
|
+
<tr>
|
133
|
+
<td>金額</td>
|
134
|
+
<td>{{property.price}}</td>
|
135
|
+
</tr>
|
136
|
+
<tr>
|
137
|
+
<td colspan="3">{{property.comment}}</td>
|
138
|
+
</tr>
|
139
|
+
</table>
|
140
|
+
{% endfor %}
|
141
|
+
|
142
|
+
{% endblock %}
|
66
143
|
```
|
1
コードを修正いたしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -46,4 +46,21 @@
|
|
46
46
|
|
47
47
|
python,djangoを始めたばかりで戸惑っております。
|
48
48
|
どなたかご教授いただけると幸いです。
|
49
|
-
ご回答の程よろしくお願いいたします。
|
49
|
+
ご回答の程よろしくお願いいたします。
|
50
|
+
|
51
|
+
修正後
|
52
|
+
```
|
53
|
+
def index(request):
|
54
|
+
propertys = Property.objects.all().order_by('-create_date')
|
55
|
+
for property in propertys:
|
56
|
+
if property.vacant_day_num == 3:
|
57
|
+
logging.debug('num is 3')
|
58
|
+
setattr(property, 'vacant_day','月、火')
|
59
|
+
logging.debug(property.vacant_day)
|
60
|
+
|
61
|
+
elif property.vacant_day_num == 96:
|
62
|
+
logging.debug('num is 96')
|
63
|
+
setattr(property, 'vacant_day','月、火、水、木、金、土、日')
|
64
|
+
logging.debug(property.vacant_day)
|
65
|
+
return render(request, 'mutual/index.html',{'propertys': propertys})
|
66
|
+
```
|