from django.db import models


class OrgManager(models.Manager):

    def get_for_user(self, user):
        return self.get_query_set().filter(users=user)


class ActiveOrgManager(OrgManager):
    """
    A more useful extension of the default manager which returns querysets
    including only active organizations
    """

    def get_query_set(self):
        return super(ActiveOrgManager,
                self).get_query_set().filter(is_active=True)

from django.db import models


class OrgManager(models.Manager):

    def get_for_user(self, user):
        if hasattr(self, 'get_queryset'):
            return self.get_queryset().filter(users=user)
        else:
            # Deprecated method for older versions of Django
            return self.get_query_set().filter(users=user)


class ActiveOrgManager(OrgManager):
    """
    A more useful extension of the default manager which returns querysets
    including only active organizations
    """

    def get_queryset(self):
        try:
            return super(ActiveOrgManager,
                    self).get_queryset().filter(is_active=True)
        except AttributeError:
            # Deprecated method for older versions of Django.
            return super(ActiveOrgManager,
                    self).get_query_set().filter(is_active=True)
    get_query_set = get_queryset

Use get_queryset method by default
Use get_queryset method by default

Adds handler for get_query_set where the former method is not available
in the base manager class.

Closes gh-48

  from django.db import models
  
  
  class OrgManager(models.Manager):
  
      def get_for_user(self, user):
+         if hasattr(self, 'get_queryset'):
+             return self.get_queryset().filter(users=user)
+         else:
+             # Deprecated method for older versions of Django
-         return self.get_query_set().filter(users=user)
+             return self.get_query_set().filter(users=user)
  
  
  class ActiveOrgManager(OrgManager):
      """
      A more useful extension of the default manager which returns querysets
      including only active organizations
      """
  
-     def get_query_set(self):
+     def get_queryset(self):
+         try:
-         return super(ActiveOrgManager,
+             return super(ActiveOrgManager,
+                     self).get_queryset().filter(is_active=True)
+         except AttributeError:
+             # Deprecated method for older versions of Django.
+             return super(ActiveOrgManager,
-                 self).get_query_set().filter(is_active=True)
+                     self).get_query_set().filter(is_active=True)
+     get_query_set = get_queryset
  
Use get_queryset method by default
## Code Before:
from django.db import models


class OrgManager(models.Manager):

    def get_for_user(self, user):
        return self.get_query_set().filter(users=user)


class ActiveOrgManager(OrgManager):
    """
    A more useful extension of the default manager which returns querysets
    including only active organizations
    """

    def get_query_set(self):
        return super(ActiveOrgManager,
                self).get_query_set().filter(is_active=True)

## Instruction:
Use get_queryset method by default
## Code After:
from django.db import models


class OrgManager(models.Manager):

    def get_for_user(self, user):
        if hasattr(self, 'get_queryset'):
            return self.get_queryset().filter(users=user)
        else:
            # Deprecated method for older versions of Django
            return self.get_query_set().filter(users=user)


class ActiveOrgManager(OrgManager):
    """
    A more useful extension of the default manager which returns querysets
    including only active organizations
    """

    def get_queryset(self):
        try:
            return super(ActiveOrgManager,
                    self).get_queryset().filter(is_active=True)
        except AttributeError:
            # Deprecated method for older versions of Django.
            return super(ActiveOrgManager,
                    self).get_query_set().filter(is_active=True)
    get_query_set = get_queryset
