M
M
Mike2016-02-01 19:06:32
Django
Mike, 2016-02-01 19:06:32

How to display all blog posts in reverse order in django?

How to display all blog posts in reverse order in django?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Sokolov, 2016-02-01
@google_online

Another option can be written in the model in the models.py file

class Post(models.Model):
    #Поля модели
    
    class Meta:
        ordering = ['-pub_date',]

Where "pub_date" is the field you want to sort the
UPD by. Yes, I forgot the brackets.

S
sim3x, 2016-02-01
@sim3x

MyModel.objects.all().order_by('-published_at')

V
Vladimir Sokolovsky, 2016-02-01
@inlanger

Try like this:

class PostListView(ListView):
    model = Post

  def get_queryset(self):
    return super(PostListView, self).get_queryset(**kwargs).order_by('-created_at')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question