#24881 closed Cleanup/optimization (fixed)
order_with_respect_to needs better docs
Reported by: | karyon | Owned by: | karyon |
---|---|---|---|
Component: | Documentation | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | karyon | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
the model meta option order_with_respect_to is documented (https://docs.djangoproject.com/en/1.8/ref/models/options/#order-with-respect-to), but i found the docs to be incomplete.
it says "Marks this object as “orderable” with respect to the given field. This is almost always used with related objects to allow them to be ordered with respect to a parent object." What i don't know is what it actually means for an object to be "orderable with respect to something". Also, these sentences only say that something is "marked" and they are "allowed" to be ordered. Under what circumstances does ordering actually happen? do i need to do something for a queryset of such objects to be ordered? And what does"almost always" mean, is there anything else this might be used for?
Also, i kinda expected this feature to order objects only when queried coming from the parent class, e.g.
Question.objects.first().answer_set()
but not order them when doing e.g.
Answer.objects.all()
because the ordering is only with respect to the parent object, right? that this is not the case might be worth mentioning explicitly.
I read some code and did experiments and from my point of view, what this actually does is:
- add a "_order" field to the model
- initializing that field when adding an instance, based on the number of other instances with the same parent (not mentioned in the docs)
- add some convenience setters/getters for that field
- set the "ordering"-option to that field (most important part and not mentioned in the docs)
I hope that helps!
Change History (8)
comment:1 by , 10 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 10 years ago
Cc: | added |
---|
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:5 by , 10 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:6 by , 10 years ago
Has patch: | set |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Thanks for the suggestions. It would be even more helpful if you could submit a patch with proposed changes.