mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #7672 -- Added a 'week_day' lookup type. Many thanks to Ross Poulton for the proposal and implementation on all built-in database backends..
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0326574d0e
commit
addd3df3bd
10 changed files with 68 additions and 15 deletions
|
@ -74,6 +74,8 @@ datetime.datetime(2005, 7, 28, 0, 0)
|
|||
<Article: Area woman programs in Python>
|
||||
>>> Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28)
|
||||
<Article: Area woman programs in Python>
|
||||
>>> Article.objects.get(pub_date__week_day=5)
|
||||
<Article: Area woman programs in Python>
|
||||
|
||||
# The "__exact" lookup type can be omitted, as a shortcut.
|
||||
>>> Article.objects.get(id=1)
|
||||
|
@ -88,6 +90,11 @@ datetime.datetime(2005, 7, 28, 0, 0)
|
|||
>>> Article.objects.filter(pub_date__year=2005, pub_date__month=7)
|
||||
[<Article: Area woman programs in Python>]
|
||||
|
||||
>>> Article.objects.filter(pub_date__week_day=5)
|
||||
[<Article: Area woman programs in Python>]
|
||||
>>> Article.objects.filter(pub_date__week_day=6)
|
||||
[]
|
||||
|
||||
# Django raises an Article.DoesNotExist exception for get() if the parameters
|
||||
# don't match any object.
|
||||
>>> Article.objects.get(id__exact=2)
|
||||
|
@ -100,6 +107,11 @@ Traceback (most recent call last):
|
|||
...
|
||||
DoesNotExist: Article matching query does not exist.
|
||||
|
||||
>>> Article.objects.get(pub_date__week_day=6)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
DoesNotExist: Article matching query does not exist.
|
||||
|
||||
# Lookup by a primary key is the most common case, so Django provides a
|
||||
# shortcut for primary-key exact lookups.
|
||||
# The following is identical to articles.get(id=1).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue