Opened 2 years ago

Closed 21 months ago

#21450 closed Cleanup/optimization (fixed)

BaseYearArchiveView prevent ordering of queryset

Reported by: Thibault Serot <thibserot@…> Owned by: nobody
Component: Generic views Version: 1.5
Severity: Normal Keywords: BaseYearArchiveView filtering
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In BaseYearArchiveView, the get_dated_items calls the get_dated_queryset with an extra parameter ordering="-%s" : qs = self.get_dated_queryset(ordering='-%s' % date_field, * * lookup_kwargs)

This behavior is not the same as in BaseMonthArchiveView (which do qs = self.get_dated_queryset(* * lookup_kwargs))
and prevents from using custom filtering in get_queryset.

Could you please remove the extra ordering="-%s" in the BaseYearArchiveView and let the user handle the filtering?

Thanks a lot

Change History (8)

comment:1 Changed 2 years ago by Thibault Serot <thibserot@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 years ago by Thibault Serot <thibserot@…>

I actually see that there is also a default filtering + ordering in BaseArchiveIndexView:

qs = self.get_dated_queryset(ordering='-%s' % self.get_date_field())
date_list = self.get_date_list(qs, ordering='DESC')

Should be replaced by:

qs = self.get_dated_queryset()
date_list = self.get_date_list()

comment:3 Changed 2 years ago by timo

Is the current behavior documented? I see some references to ordering in the docs. Would this be a backwards incompatible change for people relying on the current behavior? If we can call it a bug, we may be able to change it (and sooner rather than later would be best). Can you submit a patch with a test that demonstrates the new functionality that we'd be adding?

comment:4 follow-up: Changed 2 years ago by aaugustin

#18355 looks related.

comment:5 Changed 2 years ago by timo

  • Has patch unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

Accepting on the basis of the problem, not sure about the proposed solution at this point.

comment:6 in reply to: ↑ 4 Changed 2 years ago by pjrharley

Replying to aaugustin:

#18355 looks related.

I've added a PR there. I think it looks like it might close this ticket too if accepted. By default the behaviour is the same but the user can now easily use custom filtering (without overriding get_queryset either).

comment:7 Changed 21 months ago by Tim Graham <timograham@…>

In 2724cdbff635a40819f206411de23e9b14867a58:

Fixed #18355 -- Added ordering options to list based generic views.

Added MultipleObjectMixin.ordering and get_ordering().

Refs #21450.

comment:8 Changed 21 months ago by timgraham

  • Resolution set to fixed
  • Status changed from new to closed

Closing per above commit as I believe it solves it, but please reopen if not.

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