Changes between Version 19 and Version 20 of QuerysetRefactorBranch

04/28/08 00:36:12 (7 years ago)

Added some backwards-incompat info about order_by()


  • QuerysetRefactorBranch

    v19 v20  
    4545   }}}
    4646   This only applies to ordering by items in an `extra(select={...})` dictionary. Normal ordering is still done with the `order_by()` method to querysets, there have been no changes there. So this change will affect relatively few people.
     47 * A couple of changes to `order_by()`:
     48   * Previously, it you passed no arguments to `order_by()`, it did nothing. Now, it clears the ordering (previously there was no way to remove any existing ordering). So if you are expecting the "do nothing" behaviour, make sure to check the arguments you are passing to `order_by()` and don't call it if you have no arguments.
     49   * `order_by()` will raise an error if you try to order by a related model and resolving that model's standard ordering leads to an infinite loop (ordering by a related model tacks the target model's default ordering onto the end). This commonly comes up when ordering by a `ForeignKey` to "self". The previous code wouldn't raise an error here, but the results weren't particularly intuitive. However, if you still want the old behaviour, specify the ordering constraint explicitly so that it ends in a non-related field. For the "reference to self" case, you could make this change:
     50     {{{
     52class Tag(models.Model):
     53   parent = models.ForeignKey(self, blank=True, null=True)
     55   class Meta:
     56      # ordering = ('parent',)        # Old code now causes an infinite loop.
     57      ordering = ('parent__id',)      # Last field is a non-relation. No problem.
     58      }}}
    4860=== Other ===
Back to Top