def upvote_post(request, post_slug): if request.method != "POST": raise Http404() post = get_object_or_404(Post, slug=post_slug) post_vote, is_vote_created = PostVote.upvote( user=request.me, post=post, request=request, ) return { "post": { "upvotes": post.upvotes + (1 if is_vote_created else 0), }, "upvoted_timestamp": int(post_vote.created_at.timestamp() * 1000) }
def upvote_post(update: Update, context: CallbackContext) -> None: user = get_club_user(update) if not user: return None post = get_club_post(update) if not post: return None _, is_created = PostVote.upvote( user=user, post=post, ) if is_created: update.message.reply_text(f"Заплюсовано 👍") else: update.message.reply_text(f"Ты уже плюсовал, поц")