I
I
Iskander Mammadov2015-03-07 06:18:05
Django
Iskander Mammadov, 2015-03-07 06:18:05

How to display objects of another model in a ListView model?

There is a University model and a City model.
In views.py we create a ListView for University.
How in the ListVIew template to display objects of the City model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oscar Django, 2015-03-07
@Gugr

class UniversityListview(ListView):    
    ...
    def get_context_data(self, **kwargs):
        ctx = super(UniversityListView, self).get_context_data(**kwargs)
        ctx['cities'] = City.objects.all()
        return ctx
    ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question