Assuming that we need to bring listings from the listings model and show it on the home page which is a part of another model pages
We get the last three listings to show them on the home page pages/views.py
from listings.models import Listing
def index(request):
listings =Listing.objects.order_by(‘-list_date’).filter(is_published=True)[:3]
context = {
‘listings’ : listings
}
return render(request, ‘pages/index.html’, context)
def about(request):
return render(request, ‘pages/about.html’)
Multiple lists in context
def about(request):
realtors = Realtor.objects.order_by('-hire_date')
mvp_realtors = Realtor.objects.all().filter(is_mvp=True)
context = {
'realtors' : realtors,
'mvp_realtors' :mvp_realtors
}
return render(request, 'pages/about.html', context)