'Is it possible to edit the page_obj before passing template?
I can catch <class 'django.core.paginator.Page'> in get_context_data function of django view class.
What I want to do is alter the showing item and get it back to <class 'django.core.paginator.Page'> again.
django.core.paginator.Page source code is here.
https://docs.djangoproject.com/en/4.0/_modules/django/core/paginator/
I found it has object_list,so I try to change
def get_context_data(self):
temp = super().get_context_data()
print(type(temp['page_obj'])) #<class 'django.core.paginator.Page'>
new_object_list = []
for t in temp['page_obj'].object_list:## I can iterate the item here.
# make new_object_list here
temp['page_obj'].object_list = new_object_list
print(temp) # nothing changes
return temp
However object_list doesn't change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
