def create_notification(request, form): """Create a new notification for the post's author about new comment.""" # validate comment user is not the same than post user post = form.cleaned_data.get('post') if request.user != User.objects.get(pk=post.user.id): notification = Notification() notification.origin_user = request.user notification.target_user = User.objects.get(pk=post.user.id) notification.message = f'@{request.user} ' + _( 'commented in your post:') + f' {post.title}' notification.url = reverse('post', args=[post.id]) notification.save()