Ticket #18139: 18139.diff

File 18139.diff, 1.9 KB (added by aaugustin, 3 years ago)
  • django/views/generic/dates.py

     
    186186        Get a queryset properly filtered according to `allow_future` and any
    187187        extra lookup kwargs.
    188188        """
    189         qs = self.get_queryset().filter(**lookup)
    190189        date_field = self.get_date_field()
    191190        allow_future = self.get_allow_future()
    192191        allow_empty = self.get_allow_empty()
     192        qs = self.get_queryset().filter(**lookup).order_by('-' + date_field)
    193193        paginate_by = self.get_paginate_by(qs)
    194194
    195195        if not allow_future:
     
    236236        """
    237237        qs = self.get_dated_queryset()
    238238        date_list = self.get_date_list(qs, 'year')
    239 
    240         if date_list:
    241             object_list = qs.order_by('-' + self.get_date_field())
    242         else:
    243             object_list = qs.none()
    244 
     239        object_list = qs if date_list else qs.none()
    245240        return (date_list, object_list, {})
    246241
    247242
     
    266261        # an error if it doesn't.
    267262        year = self.get_year()
    268263        date_field = self.get_date_field()
    269         qs = self.get_dated_queryset(**{date_field+'__year': year})
     264        qs = self.get_dated_queryset(**{date_field + '__year': year})
    270265        date_list = self.get_date_list(qs, 'month')
    271266
    272         if self.get_make_object_list():
    273             object_list = qs.order_by('-'+date_field)
    274         else:
    275             # We need this to be a queryset since parent classes introspect it
    276             # to find information about the model.
    277             object_list = qs.none()
     267        # We need this to be a queryset since parent classes introspect it
     268        # to find information about the model.
     269        object_list = qs if self.get_make_object_list() else qs.none()
    278270
    279271        return (date_list, object_list, {'year': year})
    280272
Back to Top