Ticket #3134: archive_year.patch

File archive_year.patch, 1.8 KB (added by Matt, 18 years ago)

Patch to add order_by parameter to the archive_year generic view; also adds documentation for the parameter.

  • django/views/generic/date_based.py

    diff -urNp django-svn/django/views/generic/date_based.py django/django/views/generic/date_based.py
    old new def archive_index(request, queryset, dat  
    4949def archive_year(request, year, queryset, date_field, template_name=None,
    5050        template_loader=loader, extra_context=None, allow_empty=False,
    5151        context_processors=None, template_object_name='object', mimetype=None,
    52         make_object_list=False, allow_future=False):
     52        make_object_list=False, allow_future=False, order_by=None):
    5353    """
    5454    Generic yearly archive view.
    5555
    def archive_year(request, year, queryset  
    7676    if not date_list and not allow_empty:
    7777        raise Http404
    7878    if make_object_list:
    79         object_list = queryset.filter(**lookup_kwargs).order_by(date_field)
     79        order_by = order_by or date_field
     80        object_list = queryset.filter(**lookup_kwargs).order_by(order_by)
    8081    else:
    8182        object_list = []
    8283    if not template_name:
  • docs/generic_views.txt

    diff -urNp django-svn/docs/generic_views.txt django/docs/generic_views.txt
    old new to ``True``.  
    285285      specified in ``date_field`` is greater than the current date/time. By
    286286      default, this is ``False``.
    287287
     288    * ``order_by``: The name of the field in the ``QuerySet``'s model that the
     289      date-based archive should use to determine the order of the objects. By
     290      default objects are ordered chronologically by ``date_field``.
     291
    288292**Template name:**
    289293
    290294If ``template_name`` isn't specified, this view will use the template
Back to Top