def backend(request): article_list = models.Article.objects.filter(blog=request.user.blog) page_obj = Pagination(current_page=request.GET.get('page', 1), all_count=article_list.count()) page_queryset = article_list[page_obj.start:page_obj.end] return render(request, 'backend/backend.html', locals())
def boot_list(request): if request.is_ajax(): back_dic = {'code':200,'msg':''} delete_id = request.POST.get('delete_id') time.sleep(1) models.Book.objects.filter(pk=delete_id).delete() back_dic['msg'] = "删除成功" return JsonResponse(back_dic) # # ORM 的循环插入数据更快捷的方法: book_list = [] for i in range(1000): book_list.append(models.Book(title='第%s本书'%i,price=100,publish_id=100)) models.Book.objects.bulk_create(book_list) # 查询所有的书籍。 book_list = models.Book.objects.all() # 自定义分页器的使用 current_page = request.GET.get('page',1) all_count = book_list.count() page_obj = Pagination(current_page=current_page, all_count=all_count, per_page_num=15, pager_count=11) # 参数说明: # current_page 当前的页数 # all_count 所有的页数 # per_page_num 每页显示多少 # pager_count 分页器显示的条数 page_queryset = book_list[page_obj.start:page_obj.end] return render(request,'book_list.html',locals())
def backend(request): # 获取当前用户对象所有的文章展示到页面 article_list = models.Article.objects.filter(blog=request.user.blog) current_page = request.GET.get('page', 1) # 如果获取不到当前页码 就展示第一页 all_count = article_list.count() page_obj = Pagination(current_page=current_page, all_count=all_count, per_page_num=10) page_queryset = article_list[page_obj.start:page_obj.end] return render(request, "backend/backend.html", locals())
def backend(request): article_list = models.Article.objects.filter(blog=request.user.blog) # 添加分页器 # 用户想访问的当前页面 current_page = request.GET.get('page', 1) # 文章总条数 all_count = article_list.count() page_obj = Pagination(current_page=current_page, all_count=all_count) # 对数据进行切分 page_queryset = article_list[page_obj.start:page_obj.end] blog = request.user.blog return render(request, 'backend/backend.html', locals()) # 后台管理相关的单独放一个文件夹
def publish_list(request): if request.is_ajax(): delete_id = request.POST.get('delete_id') back_dict = {'code':200,'msg':''} time.sleep(1) models.Publish.objects.filter(pk=delete_id).delete() back_dict['msg'] = "删除成功" return JsonResponse(back_dict) publish_list = models.Publish.objects.all() current_page = request.GET.get('page',1) all_count = publish_list.count() page_obj = Pagination(current_page=current_page,all_count=all_count,per_page_num=10,pager_count=11) publish_queryset = publish_list[page_obj.start:page_obj.end] return render(request,'publish_list.html',locals())
def author_list(request): # l1 = [] # for i in range(1000): # l1.append(models.Author(name='作者%s'%i,email='*****@*****.**'%(i,i,i,i))) # # l1.append(models.AuthorDetail(phone='1321324%s'%i,add='上海')) # # models.AuthorDetail.objects.bulk_create(l1) # models.Author.objects.bulk_create(l1) author_list = models.Author.objects.all() current_page = request.GET.get('page',1) all_count = author_list.count() page_obj = Pagination(current_page=current_page,all_count=all_count,per_page_num=10,pager_count=11) author_querylist = author_list[page_obj.start:page_obj.end] if request.is_ajax(): delete_id = request.POST.get('delete_id') back_dict = {'code':200,'msg':''} models.Author.objects.filter(pk=delete_id).delete() back_dict['msg'] = '删除成功' return JsonResponse(back_dict) return render(request,'author_list.html',locals())