In your get_context_data()
, you have querySet
which is not defined:
def get_context_data(self, *args, **kwargs):
.....
context['purposes'] = purposes
context['querySet'] = querySet <----- Here
return context
So, you should define your querySet
like:
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs)
city = City.objects.all().annotate(
num_property=Count("property")).order_by("-num_property")
categories = Category.objects.all()
purposes = Purpose.objects.all()
featured = list(Property.objects.filter(featured=True))
querySet = self.get_queryset()
shuffle(featured)
context['city'] = city
context['categories'] = categories
context['featured'] = featured
context['purposes'] = purposes
context['querySet'] = querySet
return context
*Note:- If you are expecting querySet
from get_queryset()
, then know that these are two different methods and you defined querySet
locally. Or, you have to get that from self.get_queryset()
as mentioned by @OlegТ.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…