def post(self, request, category): if category == '原创': article = Article.objects.filter(original=category) elif category == '转载': article = Article.objects.filter(original=category) else: cate = Category.objects.get(category=category) article = Article.objects.filter(category__article=cate.id) pager = NumberDatePager() pager_list = pager.paginate_queryset(queryset=article, request=request, view=self) serializer = ArticleSerializer(instance=pager_list, many=True) try: if not pager.page.next_page_number(): return JsonResponse({'code': 404}) else: return JsonResponse({'code': 200, 'data': serializer.data}) except Exception as e: return JsonResponse({'code': 200, 'data': serializer.data})
def post(self, request): article = Article.objects.all().order_by('-view') pager = LimitDatePager() pager_list = pager.paginate_queryset(queryset=article, request=request, view=self) serializer = ArticleSerializer(instance=pager_list, many=True) return JsonResponse({'code': 200, 'data': serializer.data})
def index_item(request): if request.method == "POST": blogs = Article.objects.all() serializer = ArticleSerializer(blogs, many=True) return JsonResponse({ 'code': 200, 'message': serializer.data, 'safe': False })
def post(self, request, *args, **kwargs): fresh_list = Article.objects.all().order_by('-create_time') pager = DatePager() pager_list = pager.paginate_queryset(queryset=fresh_list, request=request, view=self) pager.get_previous_link() serializer = ArticleSerializer(instance=pager_list, many=True) return JsonResponse({ 'code': 200, 'message': serializer.data, 'safe': False })