Question

How can I display the entries of a zinnia blog in chronological order, i.e. from oldest to newest?

I tried changing and tweaking the class based view or the manager, but nothing seems to work, I always get the usual "newest-to-oldest" order.

Update: The first try was a Manager that presents the entries in chronological order.

from zinnia.managers import EntryPublishedManager

class EntryPublishedManagerFromStart(EntryPublishedManager):
    """Manager to retrieve published entries in reverse order"""

    def get_query_set(self):
        return super(EntryPublishedManagerFromStart, self
                    ).get_query_set().order_by('creation_date')

class MyEntry(EntryAbstractClass):
    """ This Entry can be displayed in chronological order. """

    fromstart = EntryPublishedManagerFromStart()

    class Meta(EntryAbstractClass.Meta):
        abstract = True

in settings.py:

ZINNIA_ENTRY_BASE_MODEL = 'blog.entry.MyEntry'

in views.py:

class EntryIndexFromStart(EntryIndex):
    """ View returning the archive index in chronological order. """
    queryset = Entry.fromstart.all

in urls.py:

...
url(r'^fromstart/?$',
    blogviews.EntryIndexFromStart.as_view(),
    name='zinnia_entry_archive_fromstart'),

But this displays the usual newest-to-oldest order. When I change the manager like this ...

    def get_query_set(self):
        return super(EntryPublishedManagerFromStart, self
                   #).get_query_set().order_by('creation_date')
                    ).get_query_set().order_by('-creation_date')

... the display is unchanged, which is weird.

The next try was a simple function based view:

def fromstart(request):
    entries = Entry.objects.filter(status=PUBLISHED).order_by('creation_date')
    return render(request, 'zinnia/entry_archive.html',
                  {'entry_list': entries,
                   'object_list': entries,
                   'is_paginated': False})

Now the entries appear from oldest to newest, but I lost the pagination.

(I'm sorry for being so terse in the first version of the question. But I thought, there had to be some easy and obvious answer for this seemingly simple requirement, and only I couldn't figure it out. I have to admit, that I still have my problems with the class based views. It's hard for me to find out where the functionality is, that I want to change.)

Maybe the problem results from Meta.ordering in zinnia.entry.CoreEntry:

class CoreEntry(models.Model):
    ...
    class Meta:
        ...
        ordering = ['-creation_date']

I don't know how to override this.

No correct solution

OTHER TIPS

Sorry, replying on a cellphone. Needs editing

You can extend Zinia's entry model Zinnia docs has a section on that. Then override Meta.ordering, as you mentioned.

Probably something like

class MyCoreMeta(CoreEntry.Meta) ordering=[´+creation_date´]

class MyCoreEntry(CoreEntry): Meta=MyCoreMeta

Then make your own abstract entry class, as explained in Zinnia docs, substituting MyCoreEntry for CoreEntry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top