質問編集履歴
2
画像の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,486 +16,480 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
![イメージ説明](2a05a8f583d4d56b5c3c04598a870e48.jpeg)
|
20
|
+
|
21
|
+
![イメージ説明](dd045aeefaecd8001eb17c8224f79e8b.png)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
### 該当のソースコード
|
26
|
+
|
27
|
+
|
28
|
+
|
19
29
|
```
|
20
30
|
|
31
|
+
# layout.html
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
{% load static %}
|
36
|
+
|
37
|
+
{% load videos %}
|
38
|
+
|
39
|
+
<!DOCTYPE html>
|
40
|
+
|
41
|
+
<html lang="ja">
|
42
|
+
|
43
|
+
<head>
|
44
|
+
|
45
|
+
<meta charset="UTF-8">
|
46
|
+
|
47
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
48
|
+
|
49
|
+
<title>動画アップロード</title>
|
50
|
+
|
51
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
|
52
|
+
|
53
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
|
54
|
+
|
55
|
+
<link rel="stylesheet" href="{% static 'videos/style.css' %}">
|
56
|
+
|
57
|
+
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
58
|
+
|
59
|
+
<link rel="stylesheet" href="{% static 'jquery-3.3.1.slim.min.js' %}">
|
60
|
+
|
61
|
+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
62
|
+
|
63
|
+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
64
|
+
|
65
|
+
crossorigin="anonymous"></script>
|
66
|
+
|
67
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
68
|
+
|
69
|
+
<script src="./js/script.js"></script>
|
70
|
+
|
71
|
+
</head>
|
72
|
+
|
73
|
+
<body>
|
74
|
+
|
75
|
+
<header>
|
76
|
+
|
77
|
+
<nav class="navbar is-dark" role="navigation" aria-label="main navigation">
|
78
|
+
|
79
|
+
<div class="navbar-brand">
|
80
|
+
|
81
|
+
<h2 class="navbar-item">video_list</h2>
|
82
|
+
|
83
|
+
<div class="buttons">
|
84
|
+
|
85
|
+
<ul class="nav_list">
|
86
|
+
|
87
|
+
<li><a href="{% url 'videos:video_list' %}" class="button is-dark">ホーム</a></li>
|
88
|
+
|
89
|
+
{% if user.is_authenticated %}
|
90
|
+
|
91
|
+
<li><a href="{% url 'videos:video_create' %}" class="button is-dark">動画投稿</a></li>
|
92
|
+
|
93
|
+
<li><a href="{% url 'videos:video_ranking' %}" class="button is-dark">ランキング</a></li>
|
94
|
+
|
95
|
+
<li><a href="{% url 'videos:search' %}" class="button is-dark">検索</a></li>
|
96
|
+
|
97
|
+
<li><a href="{% url 'videos:user_detail' user.id %}" class="button is-dark">{{ user }}</a> </li>
|
98
|
+
|
99
|
+
<li><a href="{% url 'logout' %}" class="button is-dark">Logout</a></li>
|
100
|
+
|
101
|
+
{% else %}
|
102
|
+
|
103
|
+
<li><a href="{% url 'login' %}" class="button dark">Login</a></li>
|
104
|
+
|
105
|
+
<li><a href="{% url 'accounts:signup' %}" class="button dark">SignUp</a></li>
|
106
|
+
|
107
|
+
{% endif %}
|
108
|
+
|
109
|
+
</ul>
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</nav>
|
116
|
+
|
117
|
+
<div class="nav-wrapper"><!-- ②ナビゲーションメニュー -->
|
118
|
+
|
119
|
+
<nav class="header-nav">
|
120
|
+
|
121
|
+
<ul class="nav-list">
|
122
|
+
|
123
|
+
<li class="nav-item"><a href="{% url 'videos:video_list' %}">ホーム</a></li>
|
124
|
+
|
125
|
+
{% if user.is_authenticated %}
|
126
|
+
|
127
|
+
<li class="nav-item"><a href="{% url 'videos:video_create' %}">動画投稿</a></li>
|
128
|
+
|
129
|
+
<li class="nav-item"><a href="{% url 'videos:video_ranking' %}">ランキング</a></li>
|
130
|
+
|
131
|
+
<li class="nav-item"><a href="{% url 'videos:search' %}">検索</a></li>
|
132
|
+
|
133
|
+
<li class="nav-item"><a href="{% url 'videos:user_detail' user.id %}">{{ user }}</a> </li>
|
134
|
+
|
135
|
+
<li class="nav-item"><a href="{% url 'logout' %}">Logout</a></li>
|
136
|
+
|
137
|
+
{% else %}
|
138
|
+
|
139
|
+
<li class="nav-item"><a href="{% url 'login' %}">Login</a></li>
|
140
|
+
|
141
|
+
<li class="nav-item"><a href="{% url 'accounts:signup' %}">SignUp</a></li>
|
142
|
+
|
143
|
+
{% endif %}
|
144
|
+
|
145
|
+
</ul>
|
146
|
+
|
147
|
+
</nav>
|
148
|
+
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<div class="burger-btn"><!-- ③ハンバーガーボタン -->
|
152
|
+
|
153
|
+
<span class="bar bar_top"></span>
|
154
|
+
|
155
|
+
<span class="bar bar_mid"></span>
|
156
|
+
|
157
|
+
<span class="bar bar_bottom"></span>
|
158
|
+
|
159
|
+
</div>
|
160
|
+
|
161
|
+
</header>
|
162
|
+
|
163
|
+
<div class="section">
|
164
|
+
|
165
|
+
<div class="container">
|
166
|
+
|
167
|
+
<div class="maierea">
|
168
|
+
|
169
|
+
<aside class="aside">
|
170
|
+
|
171
|
+
{% if user.is_authenticated %}
|
172
|
+
|
173
|
+
{% create_search_form request %}
|
174
|
+
|
175
|
+
{% create_category_list %}
|
176
|
+
|
177
|
+
{% endif %}
|
178
|
+
|
179
|
+
</aside>
|
180
|
+
|
181
|
+
<main>
|
182
|
+
|
183
|
+
<div class="main">
|
184
|
+
|
185
|
+
{% block content %}
|
186
|
+
|
187
|
+
{% endblock %}
|
188
|
+
|
189
|
+
</div>
|
190
|
+
|
191
|
+
</main>
|
192
|
+
|
193
|
+
</div>
|
194
|
+
|
195
|
+
</div>
|
196
|
+
|
197
|
+
</div>
|
198
|
+
|
199
|
+
</body>
|
200
|
+
|
201
|
+
</html>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
<script>
|
206
|
+
|
207
|
+
$('.burger-btn').on('click',function(){
|
208
|
+
|
209
|
+
$('.burger-btn').toggleClass('close');
|
210
|
+
|
21
|
-
|
211
|
+
$('.nav-wrapper').fadeToggle(500);
|
212
|
+
|
22
|
-
|
213
|
+
});
|
214
|
+
|
23
|
-
|
215
|
+
</script>
|
24
|
-
|
25
|
-
|
26
216
|
|
27
217
|
```
|
28
218
|
|
29
|
-
|
219
|
+
```ここに言語名を入力
|
30
|
-
|
220
|
+
|
31
|
-
#
|
221
|
+
# urls.py
|
222
|
+
|
223
|
+
|
224
|
+
|
32
|
-
|
225
|
+
from django.urls import path
|
226
|
+
|
33
|
-
|
227
|
+
from . views import (VideoList, VideoCreate, VideoUpdate, VideoDelete, VideoDetail, CommentCreate,
|
228
|
+
|
229
|
+
VideoCategoryList, CommentCreate, VideoCategoryList, UserDetail, Ranking, Search)
|
230
|
+
|
231
|
+
from .views import goodfunc, badfunc
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
app_name = 'videos'
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
urlpatterns = [
|
240
|
+
|
241
|
+
path('', VideoList.as_view(), name='video_list'),
|
242
|
+
|
243
|
+
path('create/', VideoCreate.as_view(), name='video_create'),
|
244
|
+
|
245
|
+
path('update/<int:pk>', VideoUpdate.as_view(), name='video_update'),
|
246
|
+
|
247
|
+
path('delete/<int:pk>', VideoDelete.as_view(), name='video_delete'),
|
248
|
+
|
249
|
+
path('play/<int:pk>', VideoDetail.as_view(), name='video_detail'),
|
250
|
+
|
251
|
+
path('comment/<int:pk>', CommentCreate.as_view(), name='comment_create'),
|
252
|
+
|
253
|
+
path('category/<int:pk>', VideoCategoryList.as_view(), name='video_category_list'),
|
254
|
+
|
255
|
+
path('user/<int:pk>', UserDetail.as_view(), name='user_detail'),
|
256
|
+
|
257
|
+
path('video_ranking/', Ranking.as_view(), name='video_ranking'),
|
258
|
+
|
259
|
+
path('search/', Search.as_view(), name='search'),
|
260
|
+
|
261
|
+
path('good/<int:pk>',goodfunc, name='good'),
|
262
|
+
|
263
|
+
path('bad/<int:pk>', badfunc, name='bad'),
|
264
|
+
|
265
|
+
]
|
34
266
|
|
35
267
|
```
|
36
268
|
|
269
|
+
```ここに言語名を入力
|
270
|
+
|
271
|
+
# views.py
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
from django.shortcuts import get_object_or_404, redirect, render
|
276
|
+
|
277
|
+
from django.views import generic
|
278
|
+
|
279
|
+
from django.views.generic.base import TemplateView
|
280
|
+
|
281
|
+
from .models import Video, Comment,Category
|
282
|
+
|
283
|
+
from django.urls import reverse_lazy
|
284
|
+
|
285
|
+
from django.db.models import Q
|
286
|
+
|
287
|
+
from .forms import CommentCreateForm, VideoSearchForm
|
288
|
+
|
289
|
+
from django.contrib.auth.mixins import LoginRequiredMixin
|
290
|
+
|
291
|
+
from django.core.exceptions import PermissionDenied
|
292
|
+
|
293
|
+
from django.contrib.auth.models import User
|
294
|
+
|
295
|
+
from django.views.generic import ListView
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
~~一部省略~~
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
class Ranking(LoginRequiredMixin, generic.ListView):
|
304
|
+
|
305
|
+
model = Video
|
306
|
+
|
307
|
+
template_name = 'videos/user_detail.html'
|
308
|
+
|
309
|
+
paginate_by = 9
|
310
|
+
|
311
|
+
ordering = '-good'
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
class Search(LoginRequiredMixin, generic.TemplateView):
|
316
|
+
|
317
|
+
template_name = 'videos/search.html'
|
318
|
+
|
319
|
+
def get_queryset(self):
|
320
|
+
|
321
|
+
queryset = super().get_queryset()
|
322
|
+
|
323
|
+
form = VideoSearchForm(self.request.GET or None)
|
324
|
+
|
325
|
+
if form.is_valid():
|
326
|
+
|
327
|
+
key_word = form.cleaned_data.get('key_word')
|
328
|
+
|
329
|
+
if key_word:
|
330
|
+
|
331
|
+
queryset = queryset.filter(Q(title__icontains=key_word) | Q(title__icontains=key_word))
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
return queryset
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
def goodfunc(request,pk):
|
340
|
+
|
341
|
+
object = Video.objects.get(pk=pk)
|
342
|
+
|
343
|
+
username = request.user.get_username()
|
344
|
+
|
345
|
+
if object.good == None:
|
346
|
+
|
347
|
+
object.good = 0
|
348
|
+
|
349
|
+
if object.goodtext == None:
|
350
|
+
|
351
|
+
object.goodtext = 'a'
|
352
|
+
|
353
|
+
if username in object.goodtext:
|
354
|
+
|
355
|
+
return redirect('videos:video_detail', pk=pk)
|
356
|
+
|
357
|
+
else:
|
358
|
+
|
359
|
+
object.good = object.good + 1
|
360
|
+
|
361
|
+
object.goodtext = object.goodtext + ' ' + username
|
362
|
+
|
363
|
+
object.save()
|
364
|
+
|
365
|
+
return redirect('videos:video_detail', pk=pk)
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
def badfunc(request,pk):
|
370
|
+
|
371
|
+
object = Video.objects.get(pk=pk)
|
372
|
+
|
373
|
+
username = request.user.get_username()
|
374
|
+
|
375
|
+
if object.bad == None:
|
376
|
+
|
377
|
+
object.bad = 0
|
378
|
+
|
379
|
+
if object.badtext == None:
|
380
|
+
|
381
|
+
object.badtext = 'a'
|
382
|
+
|
383
|
+
if username in object.badtext:
|
384
|
+
|
385
|
+
return redirect('videos:video_detail', pk=pk)
|
386
|
+
|
387
|
+
else:
|
388
|
+
|
389
|
+
object.bad = object.bad + 1
|
390
|
+
|
391
|
+
object.badtext = object.badtext + ' ' + username
|
392
|
+
|
393
|
+
object.save()
|
394
|
+
|
395
|
+
return redirect('videos:video_detail', pk=pk)
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
```
|
400
|
+
|
401
|
+
```ここに言語名を入力
|
402
|
+
|
37
|
-
#
|
403
|
+
# ranking.html
|
404
|
+
|
405
|
+
|
406
|
+
|
38
|
-
|
407
|
+
{% extends 'layout.html' %}
|
39
|
-
|
40
408
|
|
41
409
|
{% load static %}
|
42
410
|
|
43
411
|
{% load videos %}
|
44
412
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
<
|
54
|
-
|
55
|
-
<t
|
56
|
-
|
57
|
-
<
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
<
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
<
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
i
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
</
|
78
|
-
|
79
|
-
<
|
80
|
-
|
81
|
-
<
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
<
|
86
|
-
|
87
|
-
<h2 class="navbar-item">video_list</h2>
|
88
|
-
|
89
|
-
<div class="buttons">
|
90
|
-
|
91
|
-
<ul class="nav_list">
|
92
|
-
|
93
|
-
<li><a href="{% url 'videos:video_list' %}" class="button is-dark">ホーム</a></li>
|
94
|
-
|
95
|
-
{% if user.is_authenticated %}
|
96
|
-
|
97
|
-
<li><a href="{% url 'videos:video_create' %}" class="button is-dark">動画投稿</a></li>
|
98
|
-
|
99
|
-
<li><a href="{% url 'videos:video_ranking' %}" class="button is-dark">ランキング</a></li>
|
100
|
-
|
101
|
-
<li><a href="{% url 'videos:search' %}" class="button is-dark">検索</a></li>
|
102
|
-
|
103
|
-
<li><a href="{% url 'videos:user_detail' user.id %}" class="button is-dark">{{ user }}</a> </li>
|
104
|
-
|
105
|
-
<li><a href="{% url 'logout' %}" class="button is-dark">Logout</a></li>
|
106
|
-
|
107
|
-
{% else %}
|
108
|
-
|
109
|
-
<li><a href="{% url 'login' %}" class="button dark">Login</a></li>
|
110
|
-
|
111
|
-
<li><a href="{% url 'accounts:signup' %}" class="button dark">SignUp</a></li>
|
112
|
-
|
113
|
-
{% endif %}
|
114
|
-
|
115
|
-
</ul>
|
116
|
-
|
117
|
-
</div>
|
118
|
-
|
119
|
-
</div>
|
120
|
-
|
121
|
-
</nav>
|
122
|
-
|
123
|
-
<div class="nav-wrapper"><!-- ②ナビゲーションメニュー -->
|
124
|
-
|
125
|
-
<nav class="header-nav">
|
126
|
-
|
127
|
-
<ul class="nav-list">
|
128
|
-
|
129
|
-
<li class="nav-item"><a href="{% url 'videos:video_list' %}">ホーム</a></li>
|
130
|
-
|
131
|
-
{% if user.is_authenticated %}
|
132
|
-
|
133
|
-
<li class="nav-item"><a href="{% url 'videos:video_create' %}">動画投稿</a></li>
|
134
|
-
|
135
|
-
<li class="nav-item"><a href="{% url 'videos:video_ranking' %}">ランキング</a></li>
|
136
|
-
|
137
|
-
<li class="nav-item"><a href="{% url 'videos:search' %}">検索</a></li>
|
138
|
-
|
139
|
-
<li class="nav-item"><a href="{% url 'videos:user_detail' user.id %}">{{ user }}</a> </li>
|
140
|
-
|
141
|
-
<li class="nav-item"><a href="{% url 'logout' %}">Logout</a></li>
|
142
|
-
|
143
|
-
{% else %}
|
144
|
-
|
145
|
-
<li class="nav-item"><a href="{% url 'login' %}">Login</a></li>
|
146
|
-
|
147
|
-
<li class="nav-item"><a href="{% url 'accounts:signup' %}">SignUp</a></li>
|
148
|
-
|
149
|
-
{% endif %}
|
150
|
-
|
151
|
-
</ul>
|
152
|
-
|
153
|
-
</nav>
|
154
|
-
|
155
|
-
</div>
|
156
|
-
|
157
|
-
<div class="burger-btn"><!-- ③ハンバーガーボタン -->
|
158
|
-
|
159
|
-
<span class="bar bar_top"></span>
|
160
|
-
|
161
|
-
<span class="bar bar_mid"></span>
|
162
|
-
|
163
|
-
<span class="bar bar_bottom"></span>
|
164
|
-
|
165
|
-
</div>
|
166
|
-
|
167
|
-
</header>
|
168
|
-
|
169
|
-
<div class="section">
|
170
|
-
|
171
|
-
<div class="container">
|
172
|
-
|
173
|
-
<div class="maierea">
|
174
|
-
|
175
|
-
<aside class="aside">
|
176
|
-
|
177
|
-
{% if user.is_authenticated %}
|
178
|
-
|
179
|
-
{% create_search_form request %}
|
180
|
-
|
181
|
-
{% create_category_list %}
|
413
|
+
|
414
|
+
|
415
|
+
{% block content %}
|
416
|
+
|
417
|
+
<div class="video_list grid">
|
418
|
+
|
419
|
+
{% for video in video_list %}
|
420
|
+
|
421
|
+
<div class="video">
|
422
|
+
|
423
|
+
<h1>{{ forloop.counter }}位</h1>
|
424
|
+
|
425
|
+
<a href="{% url 'videos:video_detail' video.pk %}">
|
426
|
+
|
427
|
+
{% if video.thumbnail %}
|
428
|
+
|
429
|
+
<img src="{{ video.thumbnail.url }}">
|
430
|
+
|
431
|
+
{% else %}
|
432
|
+
|
433
|
+
<img src="{% static 'videos/noimage.png' %}">
|
434
|
+
|
435
|
+
{% endif %}
|
436
|
+
|
437
|
+
<h2>{{ video.title }}</h2>
|
438
|
+
|
439
|
+
</a>
|
440
|
+
|
441
|
+
</div>
|
442
|
+
|
443
|
+
{% endfor %}
|
444
|
+
|
445
|
+
</div>
|
446
|
+
|
447
|
+
<div class="num">
|
448
|
+
|
449
|
+
<!-- 前の部分 -->
|
450
|
+
|
451
|
+
{% if page_obj.has_previous %}
|
452
|
+
|
453
|
+
<a href="?{% url_replace request 'page' page_obj.previous_page_number %}">前へ</a>
|
182
454
|
|
183
455
|
{% endif %}
|
184
456
|
|
457
|
+
<!-- 数字の部分 -->
|
458
|
+
|
459
|
+
{% for num in page_obj.paginator.page_range %}
|
460
|
+
|
461
|
+
{% if page_obj.number == num %}
|
462
|
+
|
463
|
+
<span>{{ num }}</span>
|
464
|
+
|
465
|
+
{% else %}
|
466
|
+
|
467
|
+
<a href="?{% url_replace request 'page' num %}">{{ num }}</a>
|
468
|
+
|
469
|
+
{% endif %}
|
470
|
+
|
471
|
+
{% endfor %}
|
472
|
+
|
473
|
+
<!-- 次への部分 -->
|
474
|
+
|
475
|
+
{% if page_obj.has_next %}
|
476
|
+
|
477
|
+
<a href="?{% url_replace request 'page' page_obj.next_page_number %}">次へ</a>
|
478
|
+
|
479
|
+
{% endif %}
|
480
|
+
|
185
|
-
|
481
|
+
</div>
|
186
|
-
|
187
|
-
|
482
|
+
|
188
|
-
|
189
|
-
|
483
|
+
<div class="back_btn">
|
484
|
+
|
190
|
-
|
485
|
+
<a href='JavaScript:history.back()' class="button is-light">戻る</a>
|
486
|
+
|
191
|
-
|
487
|
+
</div>
|
192
|
-
|
488
|
+
|
193
|
-
|
489
|
+
{% endblock %}
|
194
|
-
|
195
|
-
</div>
|
196
|
-
|
197
|
-
</main>
|
198
|
-
|
199
|
-
</div>
|
200
|
-
|
201
|
-
</div>
|
202
|
-
|
203
|
-
</div>
|
204
|
-
|
205
|
-
</body>
|
206
|
-
|
207
|
-
</html>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
<script>
|
212
|
-
|
213
|
-
$('.burger-btn').on('click',function(){
|
214
|
-
|
215
|
-
$('.burger-btn').toggleClass('close');
|
216
|
-
|
217
|
-
$('.nav-wrapper').fadeToggle(500);
|
218
|
-
|
219
|
-
});
|
220
|
-
|
221
|
-
</script>
|
222
490
|
|
223
491
|
```
|
224
492
|
|
225
|
-
```ここに言語名を入力
|
226
|
-
|
227
|
-
# urls.py
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
from django.urls import path
|
232
|
-
|
233
|
-
from . views import (VideoList, VideoCreate, VideoUpdate, VideoDelete, VideoDetail, CommentCreate,
|
234
|
-
|
235
|
-
VideoCategoryList, CommentCreate, VideoCategoryList, UserDetail, Ranking, Search)
|
236
|
-
|
237
|
-
from .views import goodfunc, badfunc
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
app_name = 'videos'
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
urlpatterns = [
|
246
|
-
|
247
|
-
path('', VideoList.as_view(), name='video_list'),
|
248
|
-
|
249
|
-
path('create/', VideoCreate.as_view(), name='video_create'),
|
250
|
-
|
251
|
-
path('update/<int:pk>', VideoUpdate.as_view(), name='video_update'),
|
252
|
-
|
253
|
-
path('delete/<int:pk>', VideoDelete.as_view(), name='video_delete'),
|
254
|
-
|
255
|
-
path('play/<int:pk>', VideoDetail.as_view(), name='video_detail'),
|
256
|
-
|
257
|
-
path('comment/<int:pk>', CommentCreate.as_view(), name='comment_create'),
|
258
|
-
|
259
|
-
path('category/<int:pk>', VideoCategoryList.as_view(), name='video_category_list'),
|
260
|
-
|
261
|
-
path('user/<int:pk>', UserDetail.as_view(), name='user_detail'),
|
262
|
-
|
263
|
-
path('video_ranking/', Ranking.as_view(), name='video_ranking'),
|
264
|
-
|
265
|
-
path('search/', Search.as_view(), name='search'),
|
266
|
-
|
267
|
-
path('good/<int:pk>',goodfunc, name='good'),
|
268
|
-
|
269
|
-
path('bad/<int:pk>', badfunc, name='bad'),
|
270
|
-
|
271
|
-
]
|
272
|
-
|
273
|
-
```
|
274
|
-
|
275
|
-
```ここに言語名を入力
|
276
|
-
|
277
|
-
# views.py
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
from django.shortcuts import get_object_or_404, redirect, render
|
282
|
-
|
283
|
-
from django.views import generic
|
284
|
-
|
285
|
-
from django.views.generic.base import TemplateView
|
286
|
-
|
287
|
-
from .models import Video, Comment,Category
|
288
|
-
|
289
|
-
from django.urls import reverse_lazy
|
290
|
-
|
291
|
-
from django.db.models import Q
|
292
|
-
|
293
|
-
from .forms import CommentCreateForm, VideoSearchForm
|
294
|
-
|
295
|
-
from django.contrib.auth.mixins import LoginRequiredMixin
|
296
|
-
|
297
|
-
from django.core.exceptions import PermissionDenied
|
298
|
-
|
299
|
-
from django.contrib.auth.models import User
|
300
|
-
|
301
|
-
from django.views.generic import ListView
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
~~一部省略~~
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
class Ranking(LoginRequiredMixin, generic.ListView):
|
310
|
-
|
311
|
-
model = Video
|
312
|
-
|
313
|
-
template_name = 'videos/user_detail.html'
|
314
|
-
|
315
|
-
paginate_by = 9
|
316
|
-
|
317
|
-
ordering = '-good'
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
class Search(LoginRequiredMixin, generic.TemplateView):
|
322
|
-
|
323
|
-
template_name = 'videos/search.html'
|
324
|
-
|
325
|
-
def get_queryset(self):
|
326
|
-
|
327
|
-
queryset = super().get_queryset()
|
328
|
-
|
329
|
-
form = VideoSearchForm(self.request.GET or None)
|
330
|
-
|
331
|
-
if form.is_valid():
|
332
|
-
|
333
|
-
key_word = form.cleaned_data.get('key_word')
|
334
|
-
|
335
|
-
if key_word:
|
336
|
-
|
337
|
-
queryset = queryset.filter(Q(title__icontains=key_word) | Q(title__icontains=key_word))
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
return queryset
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
def goodfunc(request,pk):
|
346
|
-
|
347
|
-
object = Video.objects.get(pk=pk)
|
348
|
-
|
349
|
-
username = request.user.get_username()
|
350
|
-
|
351
|
-
if object.good == None:
|
352
|
-
|
353
|
-
object.good = 0
|
354
|
-
|
355
|
-
if object.goodtext == None:
|
356
|
-
|
357
|
-
object.goodtext = 'a'
|
358
|
-
|
359
|
-
if username in object.goodtext:
|
360
|
-
|
361
|
-
return redirect('videos:video_detail', pk=pk)
|
362
|
-
|
363
|
-
else:
|
364
|
-
|
365
|
-
object.good = object.good + 1
|
366
|
-
|
367
|
-
object.goodtext = object.goodtext + ' ' + username
|
368
|
-
|
369
|
-
object.save()
|
370
|
-
|
371
|
-
return redirect('videos:video_detail', pk=pk)
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
def badfunc(request,pk):
|
376
|
-
|
377
|
-
object = Video.objects.get(pk=pk)
|
378
|
-
|
379
|
-
username = request.user.get_username()
|
380
|
-
|
381
|
-
if object.bad == None:
|
382
|
-
|
383
|
-
object.bad = 0
|
384
|
-
|
385
|
-
if object.badtext == None:
|
386
|
-
|
387
|
-
object.badtext = 'a'
|
388
|
-
|
389
|
-
if username in object.badtext:
|
390
|
-
|
391
|
-
return redirect('videos:video_detail', pk=pk)
|
392
|
-
|
393
|
-
else:
|
394
|
-
|
395
|
-
object.bad = object.bad + 1
|
396
|
-
|
397
|
-
object.badtext = object.badtext + ' ' + username
|
398
|
-
|
399
|
-
object.save()
|
400
|
-
|
401
|
-
return redirect('videos:video_detail', pk=pk)
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
```
|
406
|
-
|
407
|
-
```ここに言語名を入力
|
408
|
-
|
409
|
-
# ranking.html
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
{% extends 'layout.html' %}
|
414
|
-
|
415
|
-
{% load static %}
|
416
|
-
|
417
|
-
{% load videos %}
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
{% block content %}
|
422
|
-
|
423
|
-
<div class="video_list grid">
|
424
|
-
|
425
|
-
{% for video in video_list %}
|
426
|
-
|
427
|
-
<div class="video">
|
428
|
-
|
429
|
-
<h1>{{ forloop.counter }}位</h1>
|
430
|
-
|
431
|
-
<a href="{% url 'videos:video_detail' video.pk %}">
|
432
|
-
|
433
|
-
{% if video.thumbnail %}
|
434
|
-
|
435
|
-
<img src="{{ video.thumbnail.url }}">
|
436
|
-
|
437
|
-
{% else %}
|
438
|
-
|
439
|
-
<img src="{% static 'videos/noimage.png' %}">
|
440
|
-
|
441
|
-
{% endif %}
|
442
|
-
|
443
|
-
<h2>{{ video.title }}</h2>
|
444
|
-
|
445
|
-
</a>
|
446
|
-
|
447
|
-
</div>
|
448
|
-
|
449
|
-
{% endfor %}
|
450
|
-
|
451
|
-
</div>
|
452
|
-
|
453
|
-
<div class="num">
|
454
|
-
|
455
|
-
<!-- 前の部分 -->
|
456
|
-
|
457
|
-
{% if page_obj.has_previous %}
|
458
|
-
|
459
|
-
<a href="?{% url_replace request 'page' page_obj.previous_page_number %}">前へ</a>
|
460
|
-
|
461
|
-
{% endif %}
|
462
|
-
|
463
|
-
<!-- 数字の部分 -->
|
464
|
-
|
465
|
-
{% for num in page_obj.paginator.page_range %}
|
466
|
-
|
467
|
-
{% if page_obj.number == num %}
|
468
|
-
|
469
|
-
<span>{{ num }}</span>
|
470
|
-
|
471
|
-
{% else %}
|
472
|
-
|
473
|
-
<a href="?{% url_replace request 'page' num %}">{{ num }}</a>
|
474
|
-
|
475
|
-
{% endif %}
|
476
|
-
|
477
|
-
{% endfor %}
|
478
|
-
|
479
|
-
<!-- 次への部分 -->
|
480
|
-
|
481
|
-
{% if page_obj.has_next %}
|
482
|
-
|
483
|
-
<a href="?{% url_replace request 'page' page_obj.next_page_number %}">次へ</a>
|
484
|
-
|
485
|
-
{% endif %}
|
486
|
-
|
487
|
-
</div>
|
488
|
-
|
489
|
-
<div class="back_btn">
|
490
|
-
|
491
|
-
<a href='JavaScript:history.back()' class="button is-light">戻る</a>
|
492
|
-
|
493
|
-
</div>
|
494
|
-
|
495
|
-
{% endblock %}
|
496
|
-
|
497
|
-
```
|
498
|
-
|
499
493
|
|
500
494
|
|
501
495
|
### 試したこと
|
1
画像の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,11 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
-
![
|
21
|
+
![イメージ説明](0c7a8aaace0491633426c0c7a0ed7de9.png)
|
22
|
-
|
22
|
+
|
23
|
-
![
|
23
|
+
![イメージ説明](829d82a3a6dc88eea3db5ca18da3f6c7.png)
|
24
|
+
|
25
|
+
|
24
26
|
|
25
27
|
```
|
26
28
|
|