質問編集履歴

1

コードの追加

2018/12/08 12:01

投稿

sr2460
sr2460

スコア50

test CHANGED
File without changes
test CHANGED
@@ -215,3 +215,81 @@
215
215
  情報が足りなければ適宜補足いたします。
216
216
 
217
217
  アドバイスがあればお願いいたします。
218
+
219
+
220
+
221
+
222
+
223
+ ### ご指摘を受けコードを追加いたしました
224
+
225
+
226
+
227
+ これがcommentに紐づくQuestionのコードになります。
228
+
229
+ models.py
230
+
231
+ ```ここに言語を入力
232
+
233
+ class Question(models.Model):
234
+
235
+ question_text = models.CharField(max_length=200)
236
+
237
+ pub_date = models.DateTimeField('date published')
238
+
239
+
240
+
241
+
242
+
243
+ def was_published_recently(self):
244
+
245
+ now = timezone.now()
246
+
247
+ return now - datetime.timedelta(days=1) <= self.pub_date <= now
248
+
249
+ was_published_recently.admin_order_field = 'pub_date'
250
+
251
+ was_published_recently.boolean = True
252
+
253
+ was_published_recently.short_description = 'Published recently?'
254
+
255
+
256
+
257
+ ```
258
+
259
+
260
+
261
+ またurlに関しては<int:pk>/comment/でコメントフォームを表示し<int:pk>/comment_list/でフォームで送ったコメントの一覧に遷移するようにしています。
262
+
263
+
264
+
265
+ urls.py
266
+
267
+ ```python
268
+
269
+ from django.urls import path
270
+
271
+
272
+
273
+ from . import views
274
+
275
+
276
+
277
+ app_name = 'polls'
278
+
279
+ urlpatterns = [
280
+
281
+ path('', views.IndexView.as_view(), name='index'),
282
+
283
+ path('<int:pk>/', views.DetailView.as_view(), name='detail'),
284
+
285
+ path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
286
+
287
+ path('<int:question_id>/vote/', views.vote, name='vote'),
288
+
289
+ path('<int:pk>/comment/', views.CommentView.as_view(), name='comment'),
290
+
291
+ path('<int:pk>/comment_list/', views.commentlist, name='comment_list'),
292
+
293
+ ]
294
+
295
+ ```