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