質問編集履歴

1

改善

2020/04/02 03:37

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,99 @@
97
97
  return Post.objects.filter(status=Status.objects.get(name=self.kwargs.get('stat'))).order_by('id').reverse()
98
98
 
99
99
  ```
100
+
101
+
102
+
103
+ #### 追記
104
+
105
+
106
+
107
+ ```python
108
+
109
+ class Sample(LoginRequiredMixin, ListView):
110
+
111
+ #model = Post
112
+
113
+ paginate_by = 5
114
+
115
+ template_name = 'blog/sample.html'
116
+
117
+
118
+
119
+ def get_queryset(self, **kwargs):
120
+
121
+ print('get_queryser')
122
+
123
+ return Post.objects.filter(status=Status.objects.get(name=self.kwargs.get('stat'))).order_by('id').reverse()
124
+
125
+
126
+
127
+ def get_context_data(self, **kwargs):
128
+
129
+ print('get_context_data')
130
+
131
+ context = super().get_context_data(**kwargs)
132
+
133
+ context['member'] = Member.objects.get(user=self.request.user)
134
+
135
+ print('get_context_data')
136
+
137
+ return context
138
+
139
+
140
+
141
+ def get(self, request, *args, **kwargs):
142
+
143
+ print('get')
144
+
145
+ #context = super().get_context_data(**kwargs)
146
+
147
+ #context['member'] = Member.objects.get(user=self.request.user)
148
+
149
+ #context['object_list'] = Post.objects.filter(status=Status.objects.get(name=self.kwargs.get('stat'))).order_by('id').reverse()
150
+
151
+ flag = 0
152
+
153
+
154
+
155
+ for s in Member.objects.get(user=self.request.user).status.all():
156
+
157
+ if(self.kwargs.get('stat') == str(s)):
158
+
159
+ flag += 1
160
+
161
+
162
+
163
+ if flag != 1:
164
+
165
+ return redirect('authentication:home')
166
+
167
+ else:
168
+
169
+ return render(request, 'blog/sample.html')
170
+
171
+ ```
172
+
173
+
174
+
175
+ ### 追記コンソール画面
176
+
177
+
178
+
179
+ ```shell
180
+
181
+ System check identified no issues (0 silenced).
182
+
183
+ April 02, 2020 - 12:23:15
184
+
185
+ Django version 3.0.1, using settings 'mysite.settings'
186
+
187
+ Starting development server at http://127.0.0.1:8000/
188
+
189
+ Quit the server with CTRL-BREAK.
190
+
191
+ get
192
+
193
+ [02/Apr/2020 12:23:24] "GET /blog/Vlog/ HTTP/1.1" 200 1770
194
+
195
+ ```