Ah, very good. I understand now. Thank you both for your help. On Friday, October 19, 2018 at 10:49:28 PM UTC-5, Daniel Veazey wrote: > > I'm using 2.1. I have a list of blog posts, and I want to display them > differently based on their age. The most recent post will be displayed > prominently, and the 10 most recent posts after that will be displayed in > two columns below it. The way I'm passing the view to the template is: > > class PostListView(ListView): > model = Post > template_name = 'mainapp/home.html' > > > def get_context_data(self, **kwargs): > context = super().get_context_data(**kwargs) > context['latest'] = Post.objects.all().order_by('-date_posted')[0] > context['first_column'] = Post.objects.all().order_by( > '-date_posted')[1:6] > context['second_column'] = Post.objects.all().order_by( > '-date_posted')[6:10] > return context > > Then I use 'latest', 'first_column' and 'second_column' in the template to > display those things in their separate divs. > > Doing it this way works, but I am very new and I think I might have bodged > it when there's a better way to do it. Any suggestions? >
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e717f4e2-769a-4331-a9ce-37b4ca3883e0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.