Forums

Can't get reverse ordering to work?

Puzzled by this, as it seems quite a simple thing!

Model:

class Post(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField(unique=True, max_length=255)
    description = models.CharField(max_length=255)
    content = models.TextField()
    author = models.CharField(max_length=255, default='Alex')
    published = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)

class Meta:
    ordering = ['-created']

View:

# get the blog posts that are published
posts = Post.objects.filter(published=True).order_by('-created')

I realise there's two -created commands there, but removing either one of them makes no difference.

I want the posts to display newest first (eg, descending datetime) but they steadfastly refuse to!

This was my fault! I didn't realise the query being used was actually one further down the page, added the order_by to that and it worked.