How to use the pin.models.Likes.objects function in pin

To help you get started, we’ve selected a few pin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vchakoshy / django-pin / pin / models.py View on Github external
def cnt_likes(self):
        return self.cnt_like
        #return Likes.objects.filter(post_id=self.id).count()
    
        cnt = Likes.objects.filter(post_id=self.id).count()
        Post.objects.filter(pk=self.id).update(cnt_like=cnt)
        return cnt
github vchakoshy / django-pin / pin / templatetags / pin_tags.py View on Github external
def render(self, context):
        try:
            item = int(self.item.resolve(context))
            user = context['user']
            liked = pin_likes.objects.filter(user=user, item=item).count()
            if liked:
                return 'btn-danger'
            else:
                return ''
        except template.VariableDoesNotExist:
            return ''
github vchakoshy / django-pin / pin / api.py View on Github external
def dehydrate(self, bundle):
        id = bundle.data['id']
        o_image = bundle.data['image']
        try:
            im = get_thumbnail(o_image, "300x300", quality=99, upscale=False)
        except:
            im = ""

        if im:
            bundle.data['thumbnail'] = im
            bundle.data['hw'] = "%sx%s" % (im.height, im.width)

        if self.cur_user:
            if Likes.objects.filter(post_id=bundle.data['post_id'],
                                    user=self.cur_user).count():
                bundle.data['like_with_user'] = True

        post_owner_id = bundle.data['post_owner_id']

        bundle.data['post_owner_avatar'] = userdata_cache(post_owner_id, CACHE_AVATAR)
        bundle.data['post_owner_user_name'] = userdata_cache(post_owner_id, CACHE_USERNAME)

        actors = Notif_actors.objects.filter(notif=id).order_by('id')[:10]
        ar = []
        for lk in actors:
            ar.append(
                [
                    lk.actor.id,
                    get_username(lk.actor),
                    daddy_avatar.get_avatar(lk.actor, size=100)
github vchakoshy / django-pin / pin / views.py View on Github external
def item(request, item_id):
    post = get_object_or_404(
        Post.objects.select_related().filter(id=item_id, status=1)[:1])
    Post.objects.filter(id=item_id).update(view=F('view') + 1)

    post.tag = post.tags.all()

    if request.user.is_superuser and request.GET.get('ip', None):
        post.comments = Comments.objects.filter(object_pk=post)
        post.likes = Likes.objects.filter(post=post).order_by('ip')[:10]
    else:
        post.comments = Comments.objects.filter(object_pk=post, is_public=True)
        post.likes = Likes.objects.filter(post=post)[:10]

    try:
        post.prev = Post.objects.filter(status=1)\
            .extra(where=['id<%s'], params=[post.id]).order_by('-id')[:1][0]
        post.next = Post.objects.filter(status=1)\
            .extra(where=['id>%s'], params=[post.id]).order_by('id')[:1][0]
    except:
        pass

    follow_status = Follow.objects.filter(follower=request.user.id,
                                          following=post.user.id).count()

    if request.is_ajax():
github vchakoshy / django-pin / pin / views.py View on Github external
def user_like(request, user_id):
    user_id = int(user_id)
    ROW_PER_PAGE = 20
    likes_list = []

    likes = Likes.objects.values_list('post_id', flat=True)\
        .filter(user_id=user_id).order_by('-id')

    paginator = Paginator(likes, ROW_PER_PAGE)

    try:
        offset = int(request.GET.get('older', 1))
    except ValueError:
        offset = 1

    try:
        likes = paginator.page(offset)
    except PageNotAnInteger:
        likes = paginator.page(1)
    except EmptyPage:
        return HttpResponse(0)
github vchakoshy / django-pin / pin / api.py View on Github external
return bundle


class CategotyResource(ModelResource):
    class Meta:
        queryset = Category.objects.all()
        resource_name = "category"
        #cache = SimpleCache()


class LikesResource(ModelResource):
    user_url = fields.IntegerField(attribute='user__id', null=True)
    post_id = fields.IntegerField(attribute='post_id', null=True)

    class Meta:
        queryset = Likes.objects.all()
        resource_name = 'likes'
        excludes = ['ip', 'id']
        filtering = {
            "post_id": ("exact",),
        }

    def dehydrate(self, bundle):
        user = bundle.data['user_url']
        bundle.data['user_avatar'] = userdata_cache(user, CACHE_AVATAR)
        bundle.data['user_name'] = userdata_cache(user, CACHE_USERNAME)

        return bundle


class CommentResource(ModelResource):
    user_url = fields.IntegerField(attribute='user_id', null=True)