Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…ocumentation. Thanks to anonymous for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17772 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1101739668f34a19e6e053e3bfdbf062e88db471 1 parent 86f9ab2
@jphalip jphalip authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 docs/ref/contrib/admin/index.txt
View
18 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
Please sign in to comment.
Something went wrong with that request. Please try again.