Changeset 6511
- Timestamp:
- 10/14/07 19:29:27 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/models/query.py
r6501 r6511 314 314 return obj 315 315 316 def extra(self, select=None, where=None, params=None, tables=None): 317 """ 318 Add extra SQL fragments to the query. These are applied more or less 319 verbatim (no quoting, no alias renaming, etc), so care should be taken 320 when using extra() with other complex filters and combinations. 316 def extra(self, select=None, where=None, params=None, tables=None, 317 order_by=None): 318 """ 319 Add extra SQL fragments to the query. 321 320 """ 322 321 assert self.query.can_filter(), \ … … 331 330 if tables: 332 331 clone.query.extra_tables.extend(tables) 332 if order_by: 333 clone.query.extra_order_by.extend(order_by) 333 334 return clone 334 335 django/branches/queryset-refactor/django/db/models/sql/query.py
r6510 r6511 379 379 if not self.alias_map[alias][ALIAS_REFCOUNT]: 380 380 continue 381 name, alias, join_type, lhs, lhs_col, col = \ 382 self.alias_map[alias][ALIAS_JOIN] 383 alias_str = (alias != name and ' AS %s' % alias or '') 381 join = self.alias_map[alias][ALIAS_JOIN] 382 if join: 383 name, alias, join_type, lhs, lhs_col, col = join 384 alias_str = (alias != name and ' AS %s' % alias or '') 385 else: 386 join_type = None 387 alias_str = '' 388 name = alias 384 389 if join_type: 385 390 result.append('%s %s%s ON (%s.%s = %s.%s)' … … 465 470 def find_ordering_name(self, name, opts, alias=None, default_order='ASC'): 466 471 """ 467 Returns the table alias (the name might not be unambiguous, the alias468 willbe) and column name for ordering by the given 'name' parameter.472 Returns the table alias (the name might be ambiguous, the alias will 473 not be) and column name for ordering by the given 'name' parameter. 469 474 The 'name' is of the form 'field1__field2__...__fieldN'. 470 475 """ django/branches/queryset-refactor/tests/regressiontests/queries/models.py
r6510 r6511 290 290 [<Author: a2>, <Author: a1>, <Author: a4>, <Author: a3>] 291 291 292 # Using remote model default ordering can span multiple models (in this case, 293 # Cover is ordered by Item's default, which uses Note's default). 294 >>> Cover.objects.all() 295 [<Cover: first>, <Cover: second>] 296 292 297 # If the remote model does not have a default ordering, we order by its 'id' 293 298 # field. … … 301 306 [<Ranking: 1: a3>, <Ranking: 2: a2>, <Ranking: 3: a1>] 302 307 303 >>> Cover.objects.all() 304 [<Cover: first>, <Cover: second>] 308 # Ordering of extra() pieces is possible, too and you can mix extra fields and 309 # model fields in the ordering. 310 >>> Ranking.objects.extra(tables=['django_site'], order_by=['-django_site.id', 'rank']) 311 [<Ranking: 1: a3>, <Ranking: 2: a2>, <Ranking: 3: a1>] 305 312 306 313 Bugs #2874, #3002
