回答編集履歴
2
修正
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
user = [u.user for u in Like.objects.filter(post=instance)] # ここ!
|
13
|
+
user = [u.user for u in Like.objects.filter(post=instance.post)] # ここ!
|
14
14
|
|
15
15
|
|
16
16
|
|
1
修正
test
CHANGED
@@ -2,6 +2,30 @@
|
|
2
2
|
|
3
3
|
```Python
|
4
4
|
|
5
|
-
|
5
|
+
@receiver(post_save, sender=Comment)
|
6
6
|
|
7
|
+
def comment_create_notification(sender, instance, created, **kwargs):
|
8
|
+
|
9
|
+
"""コメントが投稿されたら管理者にメールで通知する"""
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
user = [u.user for u in Like.objects.filter(post=instance)] # ここ!
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
if created:
|
18
|
+
|
19
|
+
subject = "コメント通知"
|
20
|
+
|
21
|
+
message = "お気に入り登録した投稿にコメントがつきました。"
|
22
|
+
|
23
|
+
from_email = settings.DEFAULT_FROM_EMAIL
|
24
|
+
|
25
|
+
for u in user:
|
26
|
+
|
27
|
+
recipient_list = [u.email]
|
28
|
+
|
29
|
+
send_mail(subject, message, from_email, recipient_list)
|
30
|
+
|
7
|
-
```
|
31
|
+
```たしかinstanceにPostレコードが入ってたような気がします。
|