How to use the pin.models.Post.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 / api.py View on Github external
#user_name = fields.CharField(attribute='user__username')
    #user_avatar = fields.CharField(attribute='user__email')
    user = fields.IntegerField(attribute='user_id')
    likers = fields.ListField()
    like = fields.IntegerField(attribute='cnt_like')
    category = fields.ToOneField(CategotyResource, 'category', full=True)

    like_with_user = fields.BooleanField(default=False)
    popular = None
    just_image = 0
    cur_user = None
    show_ads = True
    dispatch_exec = False

    class Meta:
        queryset = Post.objects.filter(status=1).order_by('-is_ads', '-id')
        resource_name = 'post'
        allowed_methods = ['get']
        paginator_class = Paginator
        fields = ['id', 'image', 'like', 'text', 'url', 'cnt_comment']
        #cache = SimpleCache()

    def apply_filters(self, request, applicable_filters):
        base_object_list = super(PostResource, self)\
            .apply_filters(request, applicable_filters)
        userid = request.GET.get('user_id', None)
        category_id = request.GET.get('category_id', None)
        before = request.GET.get('before', None)
        popular = request.GET.get('popular', None)
        filters = {}

        if userid:
github vchakoshy / django-pin / pin / views.py View on Github external
def category(request, cat_id):
    cat = get_object_or_404(Category, pk=cat_id)
    cat_id = cat.id
    timestamp = get_request_timestamp(request)

    if timestamp == 0:
        latest_items = Post.objects.filter(status=1, category=cat_id)\
            .order_by('-is_ads', '-timestamp')[:20]
    else:
        latest_items = Post.objects.filter(status=1, category=cat_id)\
            .extra(where=['timestamp<%s'], params=[timestamp])\
            .order_by('-timestamp')[:20]

    if request.is_ajax():
        if latest_items.exists():
            return render(request,
                          'pin/_items.html',
                          {'latest_items': latest_items})
        else:
            return HttpResponse(0)
    else:
        return render(request,
                      'pin/category.html',
github vchakoshy / django-pin / pin / admin.py View on Github external
def make_approve(self, request, queryset):
        for obj in queryset:
            Post.objects.filter(pk=obj.id)\
                .update(status=Post.APPROVED, timestamp=time.time())

        for obj in queryset:
            send_notif(user=obj.user, type=Notif.APPROVE, post=obj, actor=request.user)
github vchakoshy / django-pin / pin / admin.py View on Github external
def fault(self, request, queryset):
        for obj in queryset:
            Post.objects.filter(pk=obj.id).update(status=Post.FAULT, report=0)
            #print obj.status
            #obj.status = Post.FAULT
            #print obj.status
            #obj.save()

            user = obj.user
            user.profile.fault = user.profile.fault+1
            user.profile.save()

        for obj in queryset:
            send_notif(user=obj.user, type=Notif.FAULT, post=obj, actor=request.user)
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:
        return render(request, 'pin/item.html',
                      {'post': post, 'follow_status': follow_status})
github vchakoshy / django-pin / pin / models.py View on Github external
def delete(self, *args, **kwargs):
        Post.objects.filter(pk=self.post.id).update(cnt_like=F('cnt_like')-1)
        super(Likes, self).delete(*args, **kwargs)
github vchakoshy / django-pin / pin / feeds.py View on Github external
def items(self):
        return Post.objects.filter(status=1).order_by('-id')[:20]