Quiero ejecutar varios conjuntos de consultas desde una sola vista. Lo he hecho para que un solo get_queryset y un solo context_object_name pasen a la plantilla index.html :
class IndexView(generic.ListView): template_name = 'doorstep/index.html' context_object_name = 'all_hotels' def get_queryset(self): return Hotel.objects.all().order_by('rating').reverse()[:3] Ahora, necesito ejecutar este conjunto de consultas Hotel.objects.all().order_by('star').reverse()[:3] desde el mismo IndexView y pasar context_object_name de este conjunto de consultas al mismo template_name .
Obtengo el valor como {% for hotel in all_hotels %} en la plantilla
get_context_data y agregue cualquier conjunto de consultas adicional al contexto.
class IndexView(generic.ListView): template_name = 'doorstep/index.html' context_object_name = 'all_hotels' def get_queryset(self): return Hotel.objects.all().order_by('rating').reverse()[:3] def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context['star_hotels'] = Hotel.objects.all().order_by('star').reverse()[:3] # Add any other variables to the context here ... return context Ahora puede acceder a {{ star_hotels }} en su plantilla.