def publish_post(request): client = Client("http://127.0.0.1:8080/publish") post = Posts(user=request.user, date_created=datetime.now(), text=request.POST["text"]) post_image = "" if len(request.FILES) > 0: post.image = request.FILES["image"] post.save() post_image = post.image.url else: post.save() recieptant_list = SocialUser.objects.get( user=request.user).friends.distinct() print recieptant_list for user in recieptant_list: result = client.publish( "User_" + str(user.id), { "event": "post_added", "data": { "type": "post", "id": post.id, "creator_id": post.user.id, "creator_username": post.user.username, "text": post.text, "image": post_image, "date_created_ms": datetime_to_ms_str(post.date_created), "date_created": post.date_created.strftime("%A, %d. %B %Y %H:%M") } }) result = client.publish( "User_" + str(request.user.id), { "event": "post_added", "data": { "type": "post", "id": post.id, "creator_id": post.user.id, "creator_username": post.user.username, "text": post.text, "image": post_image, "date_created_ms": datetime_to_ms_str(post.date_created), "date_created": post.date_created.strftime("%A, %d. %B %Y %H:%M") } }) return JsonResponse({"status": "post_added", "id": post.id})