diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index a287aeecca..3c94150651 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -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