def METHOD_NAME(request, post, value):
    if not post.acl["can_like"]:
        raise PermissionDenied(
            pgettext("posts api", "You can't like posts in this category.")
        )
    # lock user to protect us from likes flood
    request.user.lock()
    # grab like state for this post and user
    try:
        user_like = post.postlike_set.get(liker=request.user)
    except PostLike.DoesNotExist:
        user_like = None
    # no change
    if (value and user_like) or (not value and not user_like):
        return {
            "likes": post.likes,
            "last_likes": post.last_likes or [],
            "is_liked": value,
        }
    # like
    if value:
        post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            liker=request.user,
            liker_name=request.user.username,
            liker_slug=request.user.slug,
        )
        post.likes += 1
    # unlike
    if not value:
        user_like.delete()
        post.likes -= 1
    post.last_likes = []
    for like in post.postlike_set.all()[:4]:
        post.last_likes.append({"id": like.liker_id, "username": like.liker_name})
    post.save(update_fields=["likes", "last_likes"])
    return {"likes": post.likes, "last_likes": post.last_likes or [], "is_liked": value}