質問編集履歴

3

情報追加

2020/06/28 09:05

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -61,111 +61,3 @@
61
61
  return render(request, 'post/delete_done.html')
62
62
 
63
63
  ```
64
-
65
-
66
-
67
- 新規投稿処理
68
-
69
- ```python
70
-
71
- class PostCreateView(CreateView):
72
-
73
- model = Post
74
-
75
- form_class = PostForm
76
-
77
- success_url = reverse_lazy('post:create_done')
78
-
79
-
80
-
81
- def form_valid(self, form):
82
-
83
- form.instance.user_id = self.request.user.id
84
-
85
- post = form.save()
86
-
87
- #return super(PostCreateView, self).form_valid(form)
88
-
89
- # 保存して編集を続けるボタン
90
-
91
- if 'save_and_edit' in self.request.POST:
92
-
93
- return redirect('post:post_update', pk=post.id)
94
-
95
- else:
96
-
97
- #return super(PostCreateView, self).form_valid(form)
98
-
99
- return redirect('post:create_done')
100
-
101
-
102
-
103
- def create_done(request):
104
-
105
- return render(request, 'post/create_done.html')
106
-
107
- ```
108
-
109
-
110
-
111
- 投稿更新処理
112
-
113
- ```python
114
-
115
- class PostUpdateView(UpdateView):
116
-
117
- model = Post
118
-
119
- form_class = PostForm
120
-
121
- success_url = reverse_lazy('post:update_done')
122
-
123
-
124
-
125
- def form_valid(self, form):
126
-
127
- post = form.save()
128
-
129
- #form.instance.user_id = self.request.user.id
130
-
131
- # 保存して編集を続けるボタン
132
-
133
- if 'save_and_edit' in self.request.POST:
134
-
135
- return redirect('post:post_update', pk=post.id)
136
-
137
- else:
138
-
139
- #return super(PostUpdateView, self).form_valid(form)
140
-
141
- return redirect('post:update_done')
142
-
143
-
144
-
145
- def update_done(request):
146
-
147
- return render(request, 'post/update_done.html')
148
-
149
- ```
150
-
151
-
152
-
153
- ```python
154
-
155
- class Post(models.Model):
156
-
157
-
158
-
159
- def get_uuid_no_dash():
160
-
161
- return uuid.uuid4().hex
162
-
163
-
164
-
165
- id = models.SlugField(primary_key=True, default=get_uuid_no_dash, editable=False)
166
-
167
- user = models.ForeignKey(User, on_delete=models.CASCADE)
168
-
169
- title = models.CharField(verbose_name='タイトル', max_length=255)
170
-
171
- ```

2

情報追加

2020/06/28 09:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -147,3 +147,25 @@
147
147
  return render(request, 'post/update_done.html')
148
148
 
149
149
  ```
150
+
151
+
152
+
153
+ ```python
154
+
155
+ class Post(models.Model):
156
+
157
+
158
+
159
+ def get_uuid_no_dash():
160
+
161
+ return uuid.uuid4().hex
162
+
163
+
164
+
165
+ id = models.SlugField(primary_key=True, default=get_uuid_no_dash, editable=False)
166
+
167
+ user = models.ForeignKey(User, on_delete=models.CASCADE)
168
+
169
+ title = models.CharField(verbose_name='タイトル', max_length=255)
170
+
171
+ ```

1

情報の修正

2020/06/27 06:23

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,131 @@
19
19
  どなたかヒントをいただけないでしょうか?
20
20
 
21
21
  必要な情報があれば追記いたします。
22
+
23
+
24
+
25
+ ユーザー削除の処理
26
+
27
+ ```python
28
+
29
+ class UserDeleteView(LoginRequiredMixin, generic.View):
30
+
31
+
32
+
33
+ def get(self, *args, **kwargs):
34
+
35
+ user = User.objects.get(email=self.request.user.email)
36
+
37
+ auth_logout(self.request)
38
+
39
+ user.delete()
40
+
41
+ return render(self.request,'user/delete_complete.html')
42
+
43
+ ```
44
+
45
+
46
+
47
+ 投稿削除処理
48
+
49
+ ```python
50
+
51
+ class PostDeleteView(DeleteView):
52
+
53
+ model = Post
54
+
55
+ success_url = reverse_lazy('post:delete_done')
56
+
57
+
58
+
59
+ def delete_done(request):
60
+
61
+ return render(request, 'post/delete_done.html')
62
+
63
+ ```
64
+
65
+
66
+
67
+ 新規投稿処理
68
+
69
+ ```python
70
+
71
+ class PostCreateView(CreateView):
72
+
73
+ model = Post
74
+
75
+ form_class = PostForm
76
+
77
+ success_url = reverse_lazy('post:create_done')
78
+
79
+
80
+
81
+ def form_valid(self, form):
82
+
83
+ form.instance.user_id = self.request.user.id
84
+
85
+ post = form.save()
86
+
87
+ #return super(PostCreateView, self).form_valid(form)
88
+
89
+ # 保存して編集を続けるボタン
90
+
91
+ if 'save_and_edit' in self.request.POST:
92
+
93
+ return redirect('post:post_update', pk=post.id)
94
+
95
+ else:
96
+
97
+ #return super(PostCreateView, self).form_valid(form)
98
+
99
+ return redirect('post:create_done')
100
+
101
+
102
+
103
+ def create_done(request):
104
+
105
+ return render(request, 'post/create_done.html')
106
+
107
+ ```
108
+
109
+
110
+
111
+ 投稿更新処理
112
+
113
+ ```python
114
+
115
+ class PostUpdateView(UpdateView):
116
+
117
+ model = Post
118
+
119
+ form_class = PostForm
120
+
121
+ success_url = reverse_lazy('post:update_done')
122
+
123
+
124
+
125
+ def form_valid(self, form):
126
+
127
+ post = form.save()
128
+
129
+ #form.instance.user_id = self.request.user.id
130
+
131
+ # 保存して編集を続けるボタン
132
+
133
+ if 'save_and_edit' in self.request.POST:
134
+
135
+ return redirect('post:post_update', pk=post.id)
136
+
137
+ else:
138
+
139
+ #return super(PostUpdateView, self).form_valid(form)
140
+
141
+ return redirect('post:update_done')
142
+
143
+
144
+
145
+ def update_done(request):
146
+
147
+ return render(request, 'post/update_done.html')
148
+
149
+ ```