Skip to content

Instantly share code, notes, and snippets.

@joncotton
Created October 7, 2013 20:46
Show Gist options
  • Select an option

  • Save joncotton/6874663 to your computer and use it in GitHub Desktop.

Select an option

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
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()
@joncotton
Copy link
Author

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.

@crccheck
Copy link

crccheck commented Oct 8, 2013

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.

@joncotton
Copy link
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