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's the correct way to do this, if there is a way?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
This is a generic example of the solution I found to my problem:
In the
forms.py
file:In the
views.py
file:You need to create the formset with the objects in the present page, otherwise, when you try to do
formset = FormSet(request.POST, request.FILES)
in the POST method, Django raises a MultiValueDictKeyError error.In the
template.html
file:More correct way to use this
The problem here is that you're using brands (a
Page
) in a context that's expecting aQuerySet
. So, we need that damnQuerySet
. You are in right way, but a lot of code.In source code we have:
So, our queryset in
self.object_list
attribute and just use it!