I am trying to build a custom administration page for my django app and I am having a problem with the changelist_view,
def changelist_view(self, request: HttpRequest, extra_context= None):
context = super().changelist_view(request, extra_context)
changelist = context.context_data.get("cl")
model = changelist.model
model_admin: ClassName = changelist.model_admin
model_instances = model.objects.all().order_by("-id")
paginator = Paginator(model_instances, 10)
page = request.GET.get("page")
try:
paginated_instances = paginator.page(page)
except PageNotAnInteger:
paginated_instances = paginator.page(1)
except EmptyPage:
paginated_instances = paginator.page(paginator.num_pages)
paginated_objects = {
"objects": paginated_instances
}
return super().changelist_view(request, extra_context= paginated_objects)
I ve made use of pagination to reduce the number of object displayed per page. When the changelist page is rendered, it works as intended but the when the next page or previous page link is clicked I get an Attribute error: context.context_data not found