2

In a prior question I asked, where a Manager's method looked like:

def activate(key):
    try:
        profile = self.get(key=key)
    except self.model.DoesNotExist:
        return None

    if not profile.key_expired():
        # -> Activate user
        return user

    return None

It was suggested to use self.get_query_set().get(key=key) instead of self.get(key=key) within the manager method. I was wondering what the reason for this is, as the former seems much more verbose?

Community
  • 1
  • 1
jvc26
  • 6,363
  • 6
  • 46
  • 75
  • 2
    It's just a convention. Like you can see in the [django source](https://code.djangoproject.com/browser/django/trunk/django/db/models/manager.py#L106), the base manager class proxies through a bunch of methods defined on QuerySets through `.get_query_set()`, so you can do `Foo.objects.get()`, `.filter()`, etc - but they all use `.get_query_set()`. Not using it shouldn't be a *problem*, really. The only difference is your tracebacks could have an extra frame from those Manager methods instead of continuing straight to the queryset. – AdamKG Feb 23 '12 at 14:54

1 Answers1

2

I guess the author just likes being verbose. There is no difference. The Manager class' get method is defined as:

def get(self, *args, **kwargs):
    return self.get_query_set().get(*args, **kwargs)

You can see it for yourself in django/db/models/manager.py

Michał Modzelewski
  • 1,320
  • 10
  • 8