Пример #1
0
    def getList(page, page_size, type):
        total = Data.objects.filter(type=type).count()
        page_count = comm.page_count(total, page_size)

        offset = (page - 1) * page_size
        limit = offset + page_size

        data_list = Data.objects.filter(type=type).order_by("-sort", "-id")[offset:limit]
        data = []
        for i in data_list:
            item = json.loads(i.toJSON())
            item["add_time"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(item["add_time"]))
            data.append(item)

        data = {"page_size": page_size, "page_count": page_count, "total": total, "page": page, "list": data}
        return data
Пример #2
0
    def getList(page, page_size):
        total = Admin.objects.all().count()
        page_count = comm.page_count(total, page_size)

        offset = (page - 1) * page_size
        limit = offset + page_size
        admin_list = Admin.objects.all().order_by("-id")[offset:limit]

        admin_list_json = []
        for admin in admin_list:
            item = json.loads(admin.toJSON())
            item["add_time"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(item["add_time"]))

            # 移除密码
            del item["pwd"]
            admin_list_json.append(item)

        data = {"page_size": page_size, "page_count": page_count, "total": total, "page": page, "list": admin_list_json}
        return data