# Path: shrubbery/db/utils.py
# def fetch(qs, *args):
#     qs = get_query_set(qs)
#     for arg in args:
#         try:
#             q = get_q(arg)
#         except ValueError:
#             if callable(arg):
#                 try:
#                     arg = arg()
#                 except qs.model.DoesNotExist:
#                     continue
#             if isinstance(arg, Exception):
#                 raise arg
#             return arg
#         try:
#             return qs.get(q)
#         except qs.model.DoesNotExist:
#             pass
#     raise qs.model.DoesNotExist()


from django.db import models
from django.db.models.query import QuerySet
from shrubbery.db.utils import fetch
        if key not in _queryset_manager_cache:
            manager_cls = type("%sManager" % queryset_cls.__name__.replace('QuerySet', ''), (cls,), {
                '__module__': queryset_cls.__module__,
                'Meta': type('Meta', (object,), {
                    'queryset': queryset_cls
                })
            })
            _queryset_manager_cache[key] = manager_cls
        return _queryset_manager_cache[key]


class QuerySetPlus(models.query.QuerySet):
    @Manager.proxy_method
    def filter(self, *args, **kwargs):
        if args and hasattr(args[0], 'add_to_query'):
            return self.complex_filter(*args)
        return super(QuerySetPlus, self).filter(*args, **kwargs)

    @Manager.proxy_method
    def exclude(self, *args, **kwargs):
        if args and hasattr(args[0], 'add_to_query'):
            try:
                q = ~args[0]
            except TypeError:
                raise TypeError('QuerySetPlus.exclude() requires a ')
            return self.complex_filter(q)
        return super(QuerySetPlus, self).exclude(*args, **kwargs)

    @Manager.proxy_method
    def fetch(self, *args):

# Path: shrubbery/db/utils.py
# def fetch(qs, *args):
#     qs = get_query_set(qs)
#     for arg in args:
#         try:
#             q = get_q(arg)
#         except ValueError:
#             if callable(arg):
#                 try:
#                     arg = arg()
#                 except qs.model.DoesNotExist:
#                     continue
#             if isinstance(arg, Exception):
#                 raise arg
#             return arg
#         try:
#             return qs.get(q)
#         except qs.model.DoesNotExist:
#             pass
#     raise qs.model.DoesNotExist()


# Path: shrubbery/db/managers.py
from django.db import models
from django.db.models.query import QuerySet
from shrubbery.db.utils import fetch

        if key not in _queryset_manager_cache:
            manager_cls = type("%sManager" % queryset_cls.__name__.replace('QuerySet', ''), (cls,), {
                '__module__': queryset_cls.__module__,
                'Meta': type('Meta', (object,), {
                    'queryset': queryset_cls
                })
            })
            _queryset_manager_cache[key] = manager_cls
        return _queryset_manager_cache[key]


class QuerySetPlus(models.query.QuerySet):
    @Manager.proxy_method
    def filter(self, *args, **kwargs):
        if args and hasattr(args[0], 'add_to_query'):
            return self.complex_filter(*args)
        return super(QuerySetPlus, self).filter(*args, **kwargs)

    @Manager.proxy_method
    def exclude(self, *args, **kwargs):
        if args and hasattr(args[0], 'add_to_query'):
            try:
                q = ~args[0]
            except TypeError:
                raise TypeError('QuerySetPlus.exclude() requires a ')
            return self.complex_filter(q)
        return super(QuerySetPlus, self).exclude(*args, **kwargs)

    @Manager.proxy_method
    def fetch(self, *args):

        return fetch(self, *args)