Changeset 2422
- Timestamp:
- 02/27/06 16:51:36 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/db/backends/ado_mssql/base.py (modified) (1 diff)
- django/branches/magic-removal/django/db/backends/mysql/base.py (modified) (1 diff)
- django/branches/magic-removal/django/db/backends/postgresql/base.py (modified) (1 diff)
- django/branches/magic-removal/django/db/backends/sqlite3/base.py (modified) (1 diff)
- django/branches/magic-removal/django/db/models/manager.py (modified) (1 diff)
- django/branches/magic-removal/django/db/models/query.py (modified) (3 diffs)
- django/branches/magic-removal/tests/modeltests/lookup/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/db/backends/ado_mssql/base.py
r1999 r2422 120 120 'contains': 'LIKE %s', 121 121 'icontains': 'LIKE %s', 122 'ne': '!= %s',123 122 'gt': '> %s', 124 123 'gte': '>= %s', django/branches/magic-removal/django/db/backends/mysql/base.py
r2033 r2422 133 133 'contains': 'LIKE BINARY %s', 134 134 'icontains': 'LIKE %s', 135 'ne': '!= %s',136 135 'gt': '> %s', 137 136 'gte': '>= %s', django/branches/magic-removal/django/db/backends/postgresql/base.py
r1999 r2422 108 108 'contains': 'LIKE %s', 109 109 'icontains': 'ILIKE %s', 110 'ne': '!= %s',111 110 'gt': '> %s', 112 111 'gte': '>= %s', django/branches/magic-removal/django/db/backends/sqlite3/base.py
r1999 r2422 132 132 'contains': "LIKE %s ESCAPE '\\'", 133 133 'icontains': "LIKE %s ESCAPE '\\'", 134 'ne': '!= %s',135 134 'gt': '> %s', 136 135 'gte': '>= %s', django/branches/magic-removal/django/db/models/manager.py
r2409 r2422 70 70 return self.get_query_set().filter(*args, **kwargs) 71 71 72 def exclude(self, *args, **kwargs): 73 return self.get_query_set().exclude(*args, **kwargs) 74 72 75 def in_bulk(self, *args, **kwargs): 73 76 return self.get_query_set().in_bulk(*args, **kwargs) django/branches/magic-removal/django/db/models/query.py
r2393 r2422 245 245 def filter(self, *args, **kwargs): 246 246 "Returns a new QuerySet instance with the args ANDed to the existing set." 247 return self._filter_or_exclude(Q, *args, **kwargs) 248 249 def exclude(self, *args, **kwargs): 250 "Returns a new QuerySet instance with NOT (arsg) ANDed to the existing set." 251 return self._filter_or_exclude(QNot, *args, **kwargs) 252 253 def _filter_or_exclude(self, qtype, *args, **kwargs): 247 254 clone = self._clone() 248 255 if len(kwargs) > 0: 249 clone._filters = clone._filters & Q(**kwargs)256 clone._filters = clone._filters & qtype(**kwargs) 250 257 if len(args) > 0: 251 258 clone._filters = clone._filters & reduce(operator.and_, args) … … 491 498 raise TypeError, other 492 499 493 class Q :500 class Q(object): 494 501 "Encapsulates queries as objects that can be combined logically." 495 502 def __init__(self, **kwargs): … … 504 511 def get_sql(self, opts): 505 512 return parse_lookup(self.kwargs.items(), opts) 513 514 class QNot(Q): 515 "Encapsulates NOT (...) queries as objects" 516 517 def get_sql(self, opts): 518 tables, joins, where, params = super(QNot, self).get_sql(opts) 519 where2 = ['(NOT (%s))' % " AND ".join(where)] 520 return tables, joins, where2, params 506 521 507 522 def get_where_clause(lookup_type, table_prefix, field_name, value): django/branches/magic-removal/tests/modeltests/lookup/models.py
r2200 r2422 171 171 >>> Article.objects.filter(headline__startswith='Article%') 172 172 [Article% with percent sign] 173 174 # exclude() is the opposite of filter() when doing lookups: 175 >>> Article.objects.filter(headline__contains='Article').exclude(headline__contains='with') 176 [Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1] 177 >>> Article.objects.exclude(headline__startswith="Article_") 178 [Article% with percent sign, Article 5, Article 6, Article 4, Article 2, Article 3, Article 7, Article 1] 179 >>> Article.objects.exclude(headline="Article 7") 180 [Article% with percent sign, Article_ with underscore, Article 5, Article 6, Article 4, Article 2, Article 3, Article 1]cl 173 181 """
