diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-15 03:32:11 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-15 03:32:11 +0000 |
| commit | a3b22d9db07ab21bda752f765b0a4414c73dee57 (patch) | |
| tree | a1c5d75642aab2d8cda3286e0b7b24421e1db743 /docs | |
| parent | f74464da52e28c513ee008022ce70717672e346e (diff) | |
queryset-refactor: Added ~ support to Q-objects. Based heavily on a patch from
Collin Grady. Refs #4858.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6518 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/db-api.txt | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt index 3906376f47..49c28d5d5a 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -211,11 +211,11 @@ Saving ForeignKey and ManyToManyField fields -------------------------------------------- Updating ``ForeignKey`` fields works exactly the same way as saving a normal -field; simply assign an object of the right type to the field in question:: +field; simply assign an object of the right type to the field in question:: - cheese_blog = Blog.objects.get(name="Cheddar Talk") - entry.blog = cheese_blog - entry.save() + cheese_blog = Blog.objects.get(name="Cheddar Talk") + entry.blog = cheese_blog + entry.save() Updating a ``ManyToManyField`` works a little differently; use the ``add()`` method on the field to add a record to the relation:: @@ -1563,6 +1563,12 @@ This is equivalent to the following SQL ``WHERE`` clause:: You can compose statements of arbitrary complexity by combining ``Q`` objects with the ``&`` and ``|`` operators. You can also use parenthetical grouping. +``Q`` objects can also be negated using the ``~`` operator, allowing for +combined lookups that combine both a normal query and a negated (``NOT``) +query:: + + Q(question__startswith='Who') | ~Q(pub_date__year=2005) + Each lookup function that takes keyword-arguments (e.g. ``filter()``, ``exclude()``, ``get()``) can also be passed one or more ``Q`` objects as positional (not-named) arguments. If you provide multiple ``Q`` object |
