You're using three different database queries. You could just fetch the most recent 11 objects, into a variable, use [0] for the most recent one. And then display the next 10 and break them into columns with css wrap.
On Sat, 20 Oct, 2018, 9:20 AM Daniel Veazey, <danielvea...@gmail.com> 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/83be2580-6e11-4b99-b854-04aa47486480%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/83be2580-6e11-4b99-b854-04aa47486480%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAA%3Diw_-Cu%2B-NtdGZeY9fC2VJ%2B13h4YWUyMY181Vez9E5E8C0Vw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.