我正在考虑访问拥有已发布评论的 content_type 的用户
目前我可以访问发布评论的用户,但是我想通知拥有该项目的人......
我试着做user = comment.content_type.user
,但我得到一个错误。
在我的主__init__.py
文件中
一旦我将其更改为user = request.user
它工作正常,但随后通知会发送给发表评论的人。
from django.contrib.comments.signals import comment_was_posted
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def comment_notification(sender, comment, request, **kwargs):
subject = comment.content_object
for role in ['user']:
if hasattr(subject, role) and isinstance(getattr(subject, role), User):
user = getattr(subject, role)
message = comment
notification.send([user], "new_comment", {'message': message,})
comment_was_posted.connect(comment_notification)