(post, request, timeout=settings.POST_VIEW_TIMEOUT)
return post
Views are updated per interval.
Views are updated per interval.
Views are updated per interval .
def update_post_views(post, request, timeout=settings.POST_VIEW_TIMEOUT):
    """
    Views are updated per interval.
    """

    # Get the ip.
    ip = helpers.get_ip(request)

    # Keys go by IP and post ip.
    cache_key = f"{ip}-{post.id}"

    # Found hit no need to increment the views
    if cache.get(cache_key):
        return

    # Insert a new view into database.
    PostView.objects.create(ip=ip, post=post)

    # Separately increment post view.
    Post.objects.filter(id=post.id).update(view_count=F('view_count') + 1)

    # Set the cache.
    cache.set(cache_key, 1, timeout)

    # Drop the post related cache for logged in users.
    if request.user.is_authenticated:
        delete_post_cache(post)

    return post
def update_post_views ( post , request , timeout = settings . POST_VIEW_TIMEOUT ) : # Get the ip. ip = helpers . get_ip ( request ) # Keys go by IP and post ip. cache_key = f"{ip}-{post.id}" # Found hit no need to increment the views if cache . get ( cache_key ) : return # Insert a new view into database. PostView . objects . create ( ip = ip , post = post ) # Separately increment post view. Post . objects . filter ( id = post . id ) . update ( view_count = F ( 'view_count' ) + 1 ) # Set the cache. cache . set ( cache_key , 1 , timeout ) # Drop the post related cache for logged in users. if request . user . is_authenticated : delete_post_cache ( post ) return post