You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have this list view that requires pagination and i have a generator for paginating but i keep getting this warning:
Cannot cache component '<class 'pages.components.multimedia_list.MultimediaListView'>' because it is not picklable: <class 'TypeError'>: cannot pickle 'generator' object
This is the code:
fromdjango.db.modelsimportQuerySetfromdjango.core.paginatorimportPaginatorfromdjango_unicorn.componentsimportUnicornViewfrompages.modelsimportMultiMediaclassMultimediaListView(UnicornView):
multimedia: QuerySet[MultiMedia] =Noneitems=Noneitems_per_page=6# Number of items to display per pagepage_index=1# Current page indexpaginator=None# Paginator objectpage=None# Current pagepage_range=None# Range of pages to displayclassMeta:
""" Meta class for additional settings. """javascript_exclude= (
"paginator",
"page",
"page_range",
"multimedia",
) # Fields to exclude from JavaScriptdefmount(self):
""" Prepares the view for rendering. """self.paginate()
defpaginate(self):
""" Paginates the multimedia based on the current page index and items per page. """paginator=Paginator(self.multimedia, self.items_per_page)
self.paginator=paginatorself.page=self.paginator.page(self.page_index)
self.page_range=self.paginator.get_elided_page_range(number=self.page_index, on_each_side=3, on_ends=2)
self.items=self.page.object_listdefgo_to_page(self, page):
""" Changes the current page to the specified page and paginates the multimedia. """self.page_index=pageself.page=''self.paginate()
Which page_range is the generator object, is there anyway to fix this?
and why pickling and caching all the attributes is necessary? like why should it be done?
The text was updated successfully, but these errors were encountered:
I have this list view that requires pagination and i have a generator for paginating but i keep getting this warning:
This is the code:
Which
page_range
is the generator object, is there anyway to fix this?and why pickling and caching all the attributes is necessary? like why should it be done?
The text was updated successfully, but these errors were encountered: