diff options
| author | Julien Phalip <jphalip@gmail.com> | 2012-03-21 05:57:22 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2012-03-21 05:57:22 +0000 |
| commit | 1101739668f34a19e6e053e3bfdbf062e88db471 (patch) | |
| tree | ec9e47eb635c47f9ca7d91736eab33b3d60fea7b /docs/ref | |
| parent | 86f9ab20b0ad3e7ad060c740adaa75f8b707d7cf (diff) | |
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
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 18 |
1 files changed, 10 insertions, 8 deletions
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 |
