How to use the pin.models.Likes 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 / 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():
        return render(request, 'pin/item_inner.html',
                      {'post': post, 'follow_status': follow_status})
    else:
github vchakoshy / django-pin / pin / models.py View on Github external
def save(self, *args, **kwargs):
        if not self.pk:
            Post.objects.filter(pk=self.post.id).update(cnt_like=F('cnt_like')+1)
        super(Likes, self).save(*args, **kwargs)
github vchakoshy / django-pin / pin / models.py View on Github external
class Comments_score(models.Model):
    comment = models.ForeignKey(Comments)
    user = models.ForeignKey(User, related_name='comment_like_user')
    score = models.IntegerField(default=0, blank=True)

class Report(models.Model):
    user = models.ForeignKey(User, related_name='report_user')
    post = models.ForeignKey(Post, related_name='report_post')
    
    class Meta:
        unique_together = (("post", "user"),)


post_save.connect(Stream.add_post, sender=Post)
post_save.connect(Likes.user_like_post, sender=Likes)
#post_delete.connect(Likes.user_unlike_post, sender=Likes)
post_save.connect(Post.change_tag_slug, sender=Tag)
post_save.connect(Notif.add_comment, sender=Comments)
github vchakoshy / django-pin / pin / api.py View on Github external
bundle.data['hw'] = "%sx%s" % (im.height, im.width)

        if int(self.just_image) == 1:
            for key in ['user', 'url', 'like', 'like_with_user',
                        'cnt_comment', 'category', 'text',
                        'image', 'likers', 'resource_uri']:
                del(bundle.data[key])

            return bundle

        bundle.data['permalink'] = '/pin/%d/' % (int(id))
        user = bundle.data['user']
        bundle.data['user_avatar'] = userdata_cache(user, CACHE_AVATAR)
        #print self.cur_user
        if self.cur_user:
            if Likes.objects.filter(post_id=id, user=self.cur_user).count():
                bundle.data['like_with_user'] = True

        bundle.data['user_name'] = userdata_cache(user, CACHE_USERNAME)
        if bundle.data['like'] == -1:
            bundle.data['like'] = 0

        if bundle.data['cnt_comment'] == -1:
            bundle.data['cnt_comment'] = 0

        if self.get_resource_uri(bundle) == bundle.request.path:
            # this is detail
            img_path = os.path.join(settings.MEDIA_ROOT, o_image)
            im = Image.open(img_path)
            w, h = im.size
            bundle.data['large_hw'] = "%sx%s" % (h, w)