How to use the pin.models.Post.objects.filter 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
if interval == 'month':
            data_from = datetime.datetime.now() - datetime.timedelta(days=30)
        elif interval == 'lastday':
            data_from = datetime.datetime.now() - datetime.timedelta(days=1)
        elif interval == 'lastweek':
            data_from = datetime.datetime.now() - datetime.timedelta(days=7)
        elif interval == 'lasteigth':
            data_from = datetime.datetime.now() - datetime.timedelta(hours=8)

        start_from = mktime(data_from.timetuple())
        post_list = Post.objects.filter(status=1)\
            .extra(where=['timestamp>%s'], params=[start_from])\
            .order_by('-cnt_like')

    else:
        post_list = Post.objects.filter(status=1)\
            .order_by('-cnt_like')
    paginator = Paginator(post_list, ROW_PER_PAGE)

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

    try:
        latest_items = paginator.page(offset)
    except PageNotAnInteger:
        latest_items = paginator.page(1)
    except EmptyPage:
        return HttpResponse(0)

    if request.is_ajax():
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 / 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:
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 / models.py View on Github external
def cnt_comments(self):
        if self.cnt_comment == -1:
            cnt = Comments.objects.filter(object_pk_id=self.id).count()
            Post.objects.filter(pk=self.id).update(cnt_comment=cnt)
        else:
            cnt = self.cnt_comment

        return cnt