Paginate Django formset

前端 未结 5 1030
失恋的感觉
失恋的感觉 2020-12-29 14:42

I have a model formset that I want to display 10 forms at a time using Django\'s Paginator, but it can\'t be done like paginator = Paginator(formset, 10). What\

5条回答
  •  Happy的楠姐
    2020-12-29 15:13

    The problem here is that you're using brands (a Page) in a context that's expecting a QuerySet. So, we need that damn QuerySet. You are in right way, but a lot of code.

    In source code we have:

    class Page(collections.Sequence):
    
        def __init__(self, object_list, number, paginator):
            self.object_list = object_list
            self.number = number
            self.paginator = paginator
            ...
    

    So, our queryset in self.object_list attribute and just use it!

    formset = SomeModelFormSet(queryset=objects.object_list)
    

提交回复
热议问题