Answer the question
In order to leave comments, you need to log in
How to force Django not to cache queryset in ListView?
Hello, there is a view, sales pages.
class SaleView(generic.ListView):
template_name = 'artskill/sale.html'
context_object_name = "products"
queryset = [SaleImages.objects.filter(state=True), Product.objects.filter(show_sale_price=True)]
Answer the question
In order to leave comments, you need to log in
What is caching? The class, together with its fields, is declared once - when the code is read by the interpreter. Accordingly, the value of the class field is defined in it until the end of the interpreter's work. If you want the value to be new each time it is accessed, use the method and return not a list, but a QuerySet:
class SaleView(generic.ListView):
template_name = 'artskill/sale.html'
context_object_name = "products"
def get_queryset(self):
return Product.objects.filter(show_sale_price=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question