how pulling a queryset from a view works

I cache my queryset, but when I do that, I still recreate that queryset, and even though I do cache my queryset, I still have to requery that queryset.
My original code was like this

class TitleDetail(DetailView):
    template_name = 'titles/detail_test.html'
    context_object_name = 'item'
    def get_qeuryset(self,**kwargs)
        key=f'titledetail:{self.kwargs["pk"]}'
        model=cache.get(key)
        if model is None:
            type = self.request.resolver_match.url_name
            id = self.kwargs['pk']
            tab = self.request.GET.get('tab')
            if not tab:
                tab = 'info'
            model = apps.get_model(app_label='titles',
                                model_name=type.split('_')[0]
                                ).objects.filter(id=id).annotate(
                **annotate_acc(type, tab)
                ).values(*values_acc(type, tab))
            cache.set(key,model)
         return model

As I understand it, when I pass my model to return it, the request happens anyway, but if I change to, let’s say something like this

return self.render_to_response({'model':model})

then it works well and i dont requery my queryset, but then i need to extract it in template with thmething like this

{%with model.0 as model%}

Is there any way to make it right in detailview

Hi Kimiyori -

in this code you have called your function ‘get_qeuryset’ instead of ‘get_queryset’ (the E and the U are in each others places), which might explain why you are getting the default ‘get_queryset’ instead of your method with caching?

oh, it’s just a typo, it’s spelled correctly in my code

This creates a queryset - but it does not execute the query to retrieve results.

Querysets are lazy. So yes, you are cacheing the queryset - not the results of the query.