質問編集履歴
1
viewsの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,37 @@
|
|
23
23
|
created_at = models.DateTimeField(verbose_name='作成日時', auto_now_add=True,null=True)
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
----views.py----
|
30
|
+
|
31
|
+
```python
|
32
|
+
|
33
|
+
def form_valid(self, form):
|
34
|
+
|
35
|
+
now = timezone.now()
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
if now - datetime.timedelta(days=7) <= self.pub_date :
|
40
|
+
|
41
|
+
messages.success(self.request, 'カウントしました。')
|
42
|
+
|
43
|
+
return super().form_valid(form)
|
44
|
+
|
45
|
+
else:
|
46
|
+
|
47
|
+
return redirect('list')
|
48
|
+
|
49
|
+
def form_invalid(self, form):
|
50
|
+
|
51
|
+
messages.error(self.request, "カウントができませんでした")
|
52
|
+
|
53
|
+
return super().form_invalid(form)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```
|