mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #10154: Allow combining F expressions with timedelta values.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f0cd656ee0
commit
b1f6a4d66f
11 changed files with 360 additions and 4 deletions
|
@ -36,6 +36,7 @@ models, which comprise a Weblog application:
|
|||
headline = models.CharField(max_length=255)
|
||||
body_text = models.TextField()
|
||||
pub_date = models.DateTimeField()
|
||||
mod_date = models.DateTimeField()
|
||||
authors = models.ManyToManyField(Author)
|
||||
n_comments = models.IntegerField()
|
||||
n_pingbacks = models.IntegerField()
|
||||
|
@ -566,10 +567,19 @@ You can also use the double underscore notation to span relationships in
|
|||
an ``F()`` object. An ``F()`` object with a double underscore will introduce
|
||||
any joins needed to access the related object. For example, to retrieve all
|
||||
the entries where the author's name is the same as the blog name, we could
|
||||
issue the query:
|
||||
issue the query::
|
||||
|
||||
>>> Entry.objects.filter(authors__name=F('blog__name'))
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
For date and date/time fields, you can add or subtract a ``datetime.timedelta``
|
||||
object. The following would return all entries that were modified more than 3 days
|
||||
after they were published::
|
||||
|
||||
>>> from datetime import timedelta
|
||||
>>> Entry.objects.filter(mod_date__gt=F('pub_date') + timedelta(days=3))
|
||||
|
||||
The pk lookup shortcut
|
||||
----------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue