QuerySet.order_by() should be chainable
|Reported by:||Joey Wilhelm||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||no|
I have a case where it would be very convenient to be able to call order_by() multiple times, appending to the order by clause with each successive call; i.e.,
foo = Model.objects.all().order_by('field1') if bar: foo = foo.order_by('-field2')
Currently, the second call to order_by() explicitly overrides the previous order. This is not the behavior I would expect, as most (all?) other methods on a QuerySet are chainable.
If it is decided that chaining will not be allowed with order_by(), then I think that this fact should at least be documented. Had I not been printing out my connection's queries when I ran into this problem, it may have taken me some time to figure out exactly what was going on.
Change History (11)
comment:8 Changed 6 years ago by
|Status:||closed → reopened|