码迷,mamicode.com
首页 > 移动开发 > 详细

django给app返回接口列表, 流式分页

时间:2019-12-30 13:00:06      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:ram   obj   post   lis   取数   nbsp   name   coding   mail   

# -*- coding: utf-8 -*-
__author__ = YongCong Wu
# @Time    : 2019/12/30 12:45
# @Email   :  : 1922878025@qq.com



class Pagenation(object):

    def __init__(self,data_list,page,per_data_num = 10):
        ‘‘‘
        初始化
        :param data_list: 所有数据列表
        :param page: 当前要查看的列表页
        :param per_data_num: 每页默认要显示几条
        ‘‘‘
        self.data_list = data_list
        self.page = page
        self.per_data_num = per_data_num

    @property
    def start(self):
        ‘‘‘
        计算引索的起始位置
        :return:
        ‘‘‘
        return (self.page - 1) * self.per_data_num

    @property
    def end(self):
        ‘‘‘
        计算引索的结束位置
        :return:
        ‘‘‘
        return self.page * self.per_data_num

    def show(self):
        ‘‘‘
        切片取数据,展示对应分页的结果
        :return:
        ‘‘‘
        result = self.data_list[self.start:self.end]
        data = []
        for row in result:
            data.append(row)
        return data
def articleNews(request, question_id):
    result = {}
    data = []
    print(question_id)
    content_list = models.AriticeModel.objects.all()
    for i in content_list:
        data_dict = {}
        data_dict[image] = i.img_url
        data_dict[id] = i.id
        data_dict[post_title] = i.title
        data_dict[post_like] = 525
        data_dict[category_name] = i.aritice_gjz
        data.append(data_dict)

    obj = pagetion.Pagenation(data, question_id)
    result[data] = obj.show()
    result[code] = 200
    return JsonResponse(result)

 

django给app返回接口列表, 流式分页

标签:ram   obj   post   lis   取数   nbsp   name   coding   mail   

原文地址:https://www.cnblogs.com/wuyongcong/p/12119164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!