django model.objects.filter for循环不会遍历所有记录

时间:2019-10-01 13:11:31

标签: python django

这件奇怪的事情发生在我身上,我试图遍历从数据库中获得的一堆记录, print(next_ghanoons.count())的值为190 但是for循环中打印的是

0 1 2,...

i直到106且从未达到190条记录 我的代码有什么问题

@staticmethod
def get_next(obj):
    current_section = obj.id_section
    current_id_book = obj.id_section.id_book.id_book
    next_order = obj.order + 1
    try:
        next_ghanoons = Ghanon.objects.filter(order=next_order)
    except ObjectDoesNotExist:
        return None
    print(next_ghanoons.count())
    i = 0
    for ghanoon in next_ghanoons:
        i = i + 1
        print(i)

0 个答案:

没有答案