質問編集履歴
3
ソースコードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,98 +20,16 @@
|
|
20
20
|
|
21
21
|
###ソースコード
|
22
22
|
|
23
|
-
|
23
|
+
base.html(抜粋)
|
24
24
|
|
25
25
|
```
|
26
26
|
|
27
|
-
f
|
27
|
+
{% if user %}
|
28
28
|
|
29
|
-
|
29
|
+
<input type="button" value="投稿" onClick="location.href='/post/new';">
|
30
30
|
|
31
|
-
|
31
|
+
<input type="button" value="ログイン" onClick="location.href='/login';">
|
32
32
|
|
33
|
-
from .forms import PostForm
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
{% endif %}
|
40
|
-
|
41
|
-
from django.contrib.auth.decorators import login_required
|
42
|
-
|
43
|
-
# login
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Create your views here.
|
50
|
-
|
51
|
-
def post_list(request):
|
52
|
-
|
53
|
-
# posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
|
54
|
-
|
55
|
-
posts = Post.objects.filter(created_date__lte=timezone.now()).order_by('-created_date')
|
56
|
-
|
57
|
-
return render(request, 'posts/post_list.html', {'posts': posts})
|
58
|
-
|
59
|
-
def post_detail(request, pk):
|
60
|
-
|
61
|
-
post = get_object_or_404(Post, pk=pk)
|
62
|
-
|
63
|
-
return render(request, 'posts/post_detail.html', {'post': post})
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
@login_required
|
68
|
-
|
69
|
-
def post_new(request):
|
70
|
-
|
71
|
-
if request.method == "POST":
|
72
|
-
|
73
|
-
form = PostForm(request.POST)
|
74
|
-
|
75
|
-
if form.is_valid():
|
76
|
-
|
77
|
-
post = form.save(commit=False)
|
78
|
-
|
79
|
-
post.author = request.user
|
80
|
-
|
81
|
-
post.save()
|
82
|
-
|
83
|
-
return redirect('/post/' + str(post.pk))
|
84
|
-
|
85
|
-
else:
|
86
|
-
|
87
|
-
form = PostForm()
|
88
|
-
|
89
|
-
return render(request, 'posts/post_edit.html', {'form': form})
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def post_edit(request, pk):
|
94
|
-
|
95
|
-
post = get_object_or_404(Post, pk=pk)
|
96
|
-
|
97
|
-
if request.method == "POST":
|
98
|
-
|
99
|
-
form = PostForm(request.POST, instance=post)
|
100
|
-
|
101
|
-
if form.is_valid():
|
102
|
-
|
103
|
-
post = form.save(commit=False)
|
104
|
-
|
105
|
-
post.author = request.user
|
106
|
-
|
107
|
-
post.save()
|
108
|
-
|
109
|
-
return redirect('/post/' + str(post.pk) + '/')
|
110
|
-
|
111
|
-
else:
|
112
|
-
|
113
|
-
form = PostForm(instance=post)
|
114
|
-
|
115
|
-
return render(request, 'posts/post_edit.html', {'form': form})
|
116
34
|
|
117
35
|
```
|
2
初心者マークの追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ログインの
|
1
|
+
ログインしているかの判定機能の実装について
|
test
CHANGED
File without changes
|