Created
October 7, 2013 20:46
-
-
Save joncotton/6874663 to your computer and use it in GitHub Desktop.
WIP for using Django 1.6's new `get_queryset()` that replaces `get_query_set()`. https://docs.djangoproject.com/en/1.6/releases/1.6/#get-query-set-and-similar-methods-renamed-to-get-queryset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_queryset(self): | |
| """Use the same ordering as TreeManager""" | |
| args = (self.model._mptt_meta.tree_id_attr, | |
| self.model._mptt_meta.left_attr) | |
| method = 'get_query_set' if django.VERSION < (1, 6) else 'get_queryset' | |
| return getattr(super(SectionManager, self), method)().order_by(*args) | |
| if django.VERSION < (1, 6): | |
| def get_query_set(self): | |
| return self.get_queryset() | |
Author
I was skimming https://groups.google.com/d/topic/django-developers/nXSpxN9RgCw/discussion and I kinda like the first approach of duplicating get_queryset and get_query_set. I'd rather have some code duplication than having version checks in the code.
Author
Just implement both and have the older function call the newer function? Or actually duplicate logic and have the super() method call its appropriate version? That second way avoids all version checking. I'm okay with that; it is a minimal amount of duplication.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is perhaps too out of context, but I didn't want to clutter the commit history of ArmSections with WIP attempts if there was a lot of discussion.