标签: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)
标签:ram obj post lis 取数 nbsp name coding mail
原文地址:https://www.cnblogs.com/wuyongcong/p/12119164.html