Changeset 6518
- Timestamp:
- 10/14/07 22:32:11 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/models/query_utils.py
r6116 r6518 41 41 return self._combine(other, self.AND) 42 42 43 def __invert__(self): 44 return QNot(self) 45 43 46 class QNot(Q): 44 47 """ … … 51 54 self.negate() 52 55 56 def __invert__(self): 57 return self.children[0] 58 django/branches/queryset-refactor/docs/db-api.txt
r6516 r6518 212 212 213 213 Updating ``ForeignKey`` fields works exactly the same way as saving a normal 214 field; simply assign an object of the right type to the field in question:: 215 216 cheese_blog = Blog.objects.get(name="Cheddar Talk") 217 entry.blog = cheese_blog 218 entry.save() 214 field; simply assign an object of the right type to the field in question:: 215 216 cheese_blog = Blog.objects.get(name="Cheddar Talk") 217 entry.blog = cheese_blog 218 entry.save() 219 219 220 220 Updating a ``ManyToManyField`` works a little differently; use the ``add()`` … … 1564 1564 with the ``&`` and ``|`` operators. You can also use parenthetical grouping. 1565 1565 1566 ``Q`` objects can also be negated using the ``~`` operator, allowing for 1567 combined lookups that combine both a normal query and a negated (``NOT``) 1568 query:: 1569 1570 Q(question__startswith='Who') | ~Q(pub_date__year=2005) 1571 1566 1572 Each lookup function that takes keyword-arguments (e.g. ``filter()``, 1567 1573 ``exclude()``, ``get()``) can also be passed one or more ``Q`` objects as django/branches/queryset-refactor/tests/modeltests/or_lookups/models.py
r6489 r6518 91 91 [<Article: Hello and goodbye>] 92 92 93 # Q objects can be negated 94 >>> Article.objects.filter(Q(pk=1) | ~Q(pk=2)) 95 [<Article: Hello>, <Article: Hello and goodbye>] 96 >>> Article.objects.filter(~Q(pk=1) & ~Q(pk=2)) 97 [<Article: Hello and goodbye>] 98 99 # This allows for more complex queries than filter() and exclude() alone would 100 # allow 101 >>> Article.objects.filter(Q(pk=1) & (~Q(pk=2) | Q(pk=3))) 102 [<Article: Hello>] 103 93 104 # Try some arg queries with operations other than get_list 94 105 >>> Article.objects.get(Q(headline__startswith='Hello'), Q(headline__contains='bye'))
