質問編集履歴

3

頂いた回答を元に作成し直しました

2019/05/29 07:41

投稿

champuyo
champuyo

スコア15

test CHANGED
File without changes
test CHANGED
@@ -409,3 +409,95 @@
409
409
 
410
410
 
411
411
  必要な情報があれば教えて頂ければ随時追加したいと思います
412
+
413
+
414
+
415
+
416
+
417
+ ###頂いた回答を元に作成し直しました。
418
+
419
+ 希望通りの動きをしています。
420
+
421
+
422
+
423
+ urls.py
424
+
425
+ ```python
426
+
427
+ from django.urls import path
428
+
429
+ from .views import ThreadListView,post_list
430
+
431
+
432
+
433
+ app_name = 'bbs'
434
+
435
+ urlpatterns = [
436
+
437
+ path('thread/', ThreadListView.as_view(), name='thread'),
438
+
439
+ path('thread/<int:pk>/', post_list, name='post'),
440
+
441
+ ]
442
+
443
+ ```
444
+
445
+
446
+
447
+ views.py
448
+
449
+ ```python
450
+
451
+ from django.shortcuts import redirect, render, get_object_or_404
452
+
453
+ from django.urls import reverse_lazy
454
+
455
+ #from django.views.generic.edit import CreateView
456
+
457
+ from django.views.generic import ListView #DetailView TemplateView
458
+
459
+ from .models import Thread,Post
460
+
461
+ from .forms import ThreadForm, PostForm
462
+
463
+
464
+
465
+ class ThreadListView(ListView):
466
+
467
+ model = Thread # Thread.objects.all()を裏側でやってくれてる
468
+
469
+ template_name = "bbs/thread.html"
470
+
471
+
472
+
473
+ def post_list(request, pk):
474
+
475
+ per_page = 10
476
+
477
+
478
+
479
+ thread = get_object_or_404(Thread,pk=pk)
480
+
481
+ post_list= Post.objects.filter(thread=thread)
482
+
483
+ form = PostForm(request.POST or None)
484
+
485
+
486
+
487
+ if form.is_valid():
488
+
489
+ post = form.save(commit=False)
490
+
491
+ post.thread = thread
492
+
493
+ post.save()
494
+
495
+ return redirect('bbs:post', pk=thread.pk)
496
+
497
+
498
+
499
+ context = {'form': form, 'post_list': post_list}
500
+
501
+ return render(request, 'bbs/post.html', context)
502
+
503
+ ```

2

ディレクトリ構造の部分をコードブロックで書き換えました

2019/05/29 07:41

投稿

champuyo
champuyo

スコア15

test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,9 @@
88
88
 
89
89
  ### 該当のソースコード
90
90
 
91
- ディレクトリ構造は、以下です。
91
+ ディレクトリ構造は、以下です。
92
+
93
+ ```
92
94
 
93
95
  ├── bbs
94
96
 
@@ -132,7 +134,7 @@
132
134
 
133
135
  └── wsgi.py
134
136
 
135
-
137
+ ```
136
138
 
137
139
 
138
140
 

1

誤字修正、画像の添付

2019/05/28 10:01

投稿

champuyo
champuyo

スコア15

test CHANGED
File without changes
test CHANGED
@@ -36,6 +36,16 @@
36
36
 
37
37
 
38
38
 
39
+ 【スレッド一覧画面↓】
40
+
41
+ ![スレッド一覧画面](4c29917a20db79983c0414753eb69789.png)
42
+
43
+ 【ユーザーの投稿一覧↓】
44
+
45
+ ![ユーザーの投稿一覧](d031518db9bcaf53f4733da5161c5f9c.png)
46
+
47
+
48
+
39
49
  ### 発生している問題・エラーメッセージ
40
50
 
41
51
 
@@ -184,7 +194,7 @@
184
194
 
185
195
 
186
196
 
187
- class PostListView(DetailView):
197
+ class PostListView(ListView):
188
198
 
189
199
  model = Post
190
200