Changeset 7220
- Timestamp:
- 03/11/08 00:21:50 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/models/sql/query.py
r7217 r7220 510 510 if not alias: 511 511 alias = self.get_initial_alias() 512 field, target, opts, joins = self.setup_joins(pieces, opts, alias, 513 False) 512 result = self.setup_joins(pieces, opts, alias, False, False) 513 if isinstance(result, int): 514 raise FieldError("Cannot order by many-valued field: '%s'" % name) 515 field, target, opts, joins = result 514 516 alias = joins[-1][-1] 515 517 col = target.column django/branches/queryset-refactor/docs/db-api.txt
r7149 r7220 541 541 542 542 ...since the ``Blog`` model has no default ordering specified. 543 544 You can only order by model fields that have a single value attached to them 545 for each instance of the model. For example, non-relations, ``ForeignKey`` and 546 ``OneToOneField`` fields. Explicitly, you can't order by a ``ManyToManyField`` 547 or a reverse ``ForeignKey`` relation. There's no naturally correct ordering 548 for many-valued fields and a lot of the alternatives are not psosible to 549 express in SQL very efficiently. 543 550 544 551 **New in Django development version:** If you don't want any ordering to be django/branches/queryset-refactor/tests/regressiontests/queries/models.py
r7217 r7220 419 419 [<Ranking: 1: a3>, <Ranking: 2: a2>, <Ranking: 3: a1>] 420 420 421 # Ordering by a many-valued attribute (e.g. a many-to-many or reverse 422 # ForeignKey) doesn't make sense (there's no natural ordering). 423 >>> Item.objects.all().order_by('tags') 424 Traceback (most recent call last): 425 ... 426 FieldError: Cannot order by many-valued field: 'tags' 427 421 428 # If we replace the default ordering, Django adjusts the required tables 422 429 # automatically. Item normally requires a join with Note to do the default
