Re: Displaying items differently on one template based on age

2018-10-20 Thread Daniel Veazey
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 >

Re: Displaying items differently on one template based on age

2018-10-19 Thread carlos
yes Joel is right you hit 3 time de DB is not good for optimization create a variable and save the one query def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) POSTS = Post.objects.all().order_by('-date_posted') context['latest'] = POSTS[0]

Re: Displaying items differently on one template based on age

2018-10-19 Thread Joel
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, wrote: > I'm using 2.1. I have

Re: Displaying items differently on one template based on age

2018-10-19 Thread Daniel Veazey
If it helps, my template looks like this: {% extends "photomanager/base.html" %} {% block content %} {% if latest.photo %} Photographer: {{ latest.photo.photographer }} Caption: {{ latest.photo.caption }} {% endif %} {{ latest.title }} {{

Displaying items differently on one template based on age

2018-10-19 Thread Daniel Veazey
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