I have a template from which I need to render information from multiple models. My models.py look something like this:
# models.py
from django.db import models
class foo(models.Model):
''' Foo content '''
class bar(models.Model):
''' Bar content '''
I also have a file views.py, from which I wrote according to this Django documentation and the answer given here, and looks something like this:
# views.py
from django.views.generic import ListView
from app.models import *
class MyView(ListView):
context_object_name = 'name'
template_name = 'page/path.html'
queryset = foo.objects.all()
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['bar'] = bar.objects.all()
return context
and my urlpatterns on urls.py have the following object:
url(r'^path$',views.MyView.as_view(), name = 'name'),
My question is, on the template page/path.html how can I reference the objects and the object properties from foo and bar to display them in my page?