Consider a different interface for get_next_by_FOO and get_previous_by_FOO
|Reported by:||umbrae@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Recently I was looking to use these methods along with a deferred query. As I quickly found out, it's impossible - in order to defer I'll have to implement all of the get_next_by logic separately. That's because these methods are tied directly to a model. You can't defer because it's not part of a manager.
I'm no django expert (yet), but I'm wondering if these methods might be better suited, in the long term, off of .objects instead - so something like the following would work:
some_blog = Blog.objects.get(pk=1) # Get the next one by passing in a model older_blog = Blog.objects.get_next_by_date_added(some_blog) # Get the next one by passing in a datetime object itself older_blog = Blog.objects.get_next_by_date_added(some_blog.date_added) # Get the next blog, but don't get pull out content because it's unnecessary. deferred_older_blog = Blog.objects.defer('content').get_next_by_date_added(some_blog)
Any thoughts here?
Change History (4)
comment:1 Changed 4 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed