回答編集履歴
2
コードが間違っていたので修正
test
CHANGED
@@ -65,3 +65,81 @@
|
|
65
65
|
|
66
66
|
|
67
67
|
view.pyへの記載ではなくテンプレートへの記載のみで解決できました!
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
上記のコード誤っておりました!
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
models.py
|
78
|
+
|
79
|
+
```python
|
80
|
+
|
81
|
+
class Question(models.Model):
|
82
|
+
|
83
|
+
question_text = models.CharField(max_length=200)
|
84
|
+
|
85
|
+
pub_date = models.DateTimeField('date published')
|
86
|
+
|
87
|
+
date_limit = models.DateTimeField('公開期限', default = timezone.now() + timedelta(days=7) )
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def is_date_limit(self):
|
92
|
+
|
93
|
+
# まだ公開期限を過ぎていないならTrue
|
94
|
+
|
95
|
+
now = timezone.now()
|
96
|
+
|
97
|
+
return now <= self.date_limit
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
detail.html
|
104
|
+
|
105
|
+
```html
|
106
|
+
|
107
|
+
{% if question.is_date_limit %}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<form action="{% url 'polls:vote' question.id %}" method="POST">
|
118
|
+
|
119
|
+
{{ form.non_field_errors }}
|
120
|
+
|
121
|
+
{% for field in form %}
|
122
|
+
|
123
|
+
<div class="form-group">
|
124
|
+
|
125
|
+
<label for="{{ field.id_for_label }}">{{ field.label_tag }}</label>
|
126
|
+
|
127
|
+
{{ field }}
|
128
|
+
|
129
|
+
{{ field.errors }}
|
130
|
+
|
131
|
+
</div>
|
132
|
+
|
133
|
+
{% endfor %}
|
134
|
+
|
135
|
+
{% csrf_token %}
|
136
|
+
|
137
|
+
<button type="submit" class="btn btn-dark">送信</button>
|
138
|
+
|
139
|
+
</form>
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
{% endif %}
|
144
|
+
|
145
|
+
```
|
1
文章を修正
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
自己解決いたしました。
|
2
2
|
|
3
|
-
テンプレート
|
3
|
+
テンプレートを以下のように改造。
|
4
4
|
|
5
5
|
|
6
6
|
|