投稿されたコメントの 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)