mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
86f9ab20b0
commit
1101739668
|
@ -606,6 +606,8 @@ subclass::
|
||||||
attributes to and override the ``lookups`` and ``queryset`` methods,
|
attributes to and override the ``lookups`` and ``queryset`` methods,
|
||||||
e.g.::
|
e.g.::
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.contrib.admin import SimpleListFilter
|
from django.contrib.admin import SimpleListFilter
|
||||||
|
|
||||||
|
@ -639,11 +641,11 @@ subclass::
|
||||||
# Compare the requested value (either '80s' or 'other')
|
# Compare the requested value (either '80s' or 'other')
|
||||||
# to decide how to filter the queryset.
|
# to decide how to filter the queryset.
|
||||||
if self.value() == '80s':
|
if self.value() == '80s':
|
||||||
return queryset.filter(birthday__year__gte=1980,
|
return queryset.filter(birthday__gte=date(1980, 1, 1),
|
||||||
birthday__year__lte=1989)
|
birthday__lte=date(1989, 12, 31))
|
||||||
if self.value() == '90s':
|
if self.value() == '90s':
|
||||||
return queryset.filter(birthday__year__gte=1990,
|
return queryset.filter(birthday__gte=date(1990, 1, 1),
|
||||||
birthday__year__lte=1999)
|
birthday__lte=date(1999, 12, 31))
|
||||||
|
|
||||||
class PersonAdmin(ModelAdmin):
|
class PersonAdmin(ModelAdmin):
|
||||||
list_filter = (DecadeBornListFilter,)
|
list_filter = (DecadeBornListFilter,)
|
||||||
|
@ -677,11 +679,11 @@ subclass::
|
||||||
anyone born in the corresponding decades.
|
anyone born in the corresponding decades.
|
||||||
"""
|
"""
|
||||||
qs = model_admin.queryset(request)
|
qs = model_admin.queryset(request)
|
||||||
if qs.filter(birthday__year__gte=1980,
|
if qs.filter(birthday__gte=date(1980, 1, 1),
|
||||||
birthday__year__lte=1989).exists():
|
birthday__lte=date(1989, 12, 31)).exists():
|
||||||
yield ('80s', _('in the eighties'))
|
yield ('80s', _('in the eighties'))
|
||||||
if qs.filter(birthday__year__gte=1990,
|
if qs.filter(birthday__gte=date(1990, 1, 1),
|
||||||
birthday__year__lte=1999).exists():
|
birthday__lte=date(1999, 12, 31)).exists():
|
||||||
yield ('90s', _('in the nineties'))
|
yield ('90s', _('in the nineties'))
|
||||||
|
|
||||||
* a tuple, where the first element is a field name and the second
|
* a tuple, where the first element is a field name and the second
|
||||||
|
|
Loading…
Reference in New Issue