[Solved]-Can I have multiple lists in a Django generic.ListView?

15👍

Absolutely, you’ll just need to write your own ‘get_context_data’ method that will retrieve those values and then they will be available in the view. Something like:

def get_context_data(self, *args, **kwargs):
    context = super(IndexView, self).get_context_data(*args, **kwargs)
    context['alphabetical_poll_list'] = Poll.objects.order_by('name')[:5]
    return context 

With this both {{ latest_poll_list }} and {{ alphabetical_poll_list }} would be available in your template.

Leave a comment