Exemplo n.º 1
0
def incr_comments_count(sender, instance, created, **kwargs):
    from django.db.models import F
    from tweets.models import Tweet
    from util.redis_helper import RedisHelper

    if not created:
        return

    Tweet.objects.filter(id=instance.tweet_id).update(
        comments_count=F('comments_count') + 1)
    RedisHelper.incr_count(instance.tweet, 'comments_count')
Exemplo n.º 2
0
def incr_likes_count(sender, instance, created, **kwargs):
    from django.db.models import F
    from tweets.models import Tweet
    from util.redis_helper import RedisHelper

    if not created:
        return

    model_class = instance.content_type.model_class()

    if model_class != Tweet:
        # TODO: support likes for comments.
        return

    Tweet.objects.filter(id=instance.object_id).update(
        likes_count=F('likes_count') + 1)
    tweet = instance.content_object
    RedisHelper.incr_count(tweet, 'likes_count')