Opened 19 years ago

Closed 18 years ago

#1381 closed defect (worksforme)

'django.views.generic.date_based.archive_index' doesn't return latest objects first

Reported by: jakamkon@… Owned by: Jacob
Component: Generic views Version: dev
Severity: trivial Keywords: django.views.generic.date_based.archive_index archive_index
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In django/views/generic/data_based.py we have:

def archive_index:
  ...
  lookup_kwargs = {'%s__lte' % date_field: datetime.datetime.now()} # *
  ...
  date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1]

Consider situation:

some_model.get_date_list('year')
[datetime.datetime(2005, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)]

some_model.get_date_list('year', date__lte=datetime.now()) # situation as in *
[datetime.datetime(2005, 1, 1, 0, 0)] # we get the oldest year

In other words we get the oldest objects in place of the latest in our view.

When * is changed to:

 lookup_kwargs = {'%s__gte' % date_field: datetime.datetime.now()}

Now, we get the latest date:

some_model.get_date_list('year', date__gte=datetime.now())
[datetime.datetime(2006, 1, 1, 0, 0)]

      

Change History (2)

comment:1 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Malcolm Tredinnick, 18 years ago

Resolution: worksforme
Status: newclosed

This has been fixed in the interim at some point.

Note: See TracTickets for help on using tickets.
Back to Top