From b1f6a4d66fd7f987a41c1e1aaa43907d9d347ba6 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Wed, 22 Dec 2010 03:34:04 +0000 Subject: 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 --- docs/releases/1.3.txt | 3 +++ docs/topics/db/queries.txt | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt index 0bf212452e..7992c95e5f 100644 --- a/docs/releases/1.3.txt +++ b/docs/releases/1.3.txt @@ -235,6 +235,9 @@ requests. These include: providing a :class:`~django.template.RequestContext` by default. + * Support for combining :ref:`F() expressions ` + with timedelta values when retrieving or updating database values. + .. _HTTPOnly: http://www.owasp.org/index.php/HTTPOnly .. _backwards-incompatible-changes-1.3: diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 2141aa6e91..cbbf073d39 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -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 ---------------------- -- cgit v1.3