Commit 11017396 authored by Julien Phalip's avatar Julien Phalip
Browse files

Fixed #17936 -- Fixed a code sample in the admin `SimpleListFilter`...

Fixed #17936 -- Fixed a code sample in the admin `SimpleListFilter` documentation. Thanks to anonymous for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17772 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 86f9ab20
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -606,6 +606,8 @@ subclass::
      attributes to and override the ``lookups`` and ``queryset`` methods,
      e.g.::

           from datetime import date

           from django.utils.translation import ugettext_lazy as _
           from django.contrib.admin import SimpleListFilter

@@ -639,11 +641,11 @@ subclass::
                   # Compare the requested value (either '80s' or 'other')
                   # to decide how to filter the queryset.
                   if self.value() == '80s':
                       return queryset.filter(birthday__year__gte=1980,
                                               birthday__year__lte=1989)
                       return queryset.filter(birthday__gte=date(1980, 1, 1),
                                               birthday__lte=date(1989, 12, 31))
                   if self.value() == '90s':
                       return queryset.filter(birthday__year__gte=1990,
                                              birthday__year__lte=1999)
                       return queryset.filter(birthday__gte=date(1990, 1, 1),
                                               birthday__lte=date(1999, 12, 31))

           class PersonAdmin(ModelAdmin):
               list_filter = (DecadeBornListFilter,)
@@ -677,11 +679,11 @@ subclass::
                      anyone born in the corresponding decades.
                      """
                      qs = model_admin.queryset(request)
                      if qs.filter(birthday__year__gte=1980,
                                    birthday__year__lte=1989).exists():
                      if qs.filter(birthday__gte=date(1980, 1, 1),
                                    birthday__lte=date(1989, 12, 31)).exists():
                          yield ('80s', _('in the eighties'))
                      if qs.filter(birthday__year__gte=1990,
                                    birthday__year__lte=1999).exists():
                      if qs.filter(birthday__gte=date(1990, 1, 1),
                                    birthday__lte=date(1999, 12, 31)).exists():
                          yield ('90s', _('in the nineties'))

    * a tuple, where the first element is a field name and the second