# Path: shrubbery/db/utils.py
# def no_related_name(hidden=False):
#     no_related_name._next += 1
#     name = "_no_related_name_%%(class)s_%s" % (no_related_name._next)
#     if hidden:
#         name += '+'
#     return name


from django.db import models as django_models
from shrubbery.db.utils import no_related_name
    from south.modelsinspector import add_introspection_rules


class ForeignRelatedObjectsDescriptor(django_models.fields.related.ForeignRelatedObjectsDescriptor):
    def create_manager(self, instance, superclass):
        field = self.related.field
        superclass = field.related_manager_class or superclass
        cls = super(ForeignRelatedObjectsDescriptor, self).create_manager(instance, superclass)
        if field.related_manager_class_decorator:
            cls = field.related_manager_class_decorator(cls)
        return cls


class ForeignKey(django_models.ForeignKey):
    def __init__(self, *args, **kwargs):
        self.related_manager_class = kwargs.pop('related_manager_class', None)
        self.related_manager_class_decorator = kwargs.pop('related_manager_class_decorator', None)

        if 'related_name' in kwargs and not kwargs['related_name']:
            kwargs['related_name'] = no_related_name()
        super(ForeignKey, self).__init__(*args, **kwargs)

    def contribute_to_related_class(self, cls, related):
        super(ForeignKey, self).contribute_to_related_class(cls, related)
        if self.related_manager_class or self.related_manager_class_decorator:
            setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))


class OneToOneField(django_models.OneToOneField):
    def __init__(self, *args, **kwargs):
        if 'related_name' in kwargs and not kwargs['related_name']:

# Path: shrubbery/db/utils.py
# def no_related_name(hidden=False):
#     no_related_name._next += 1
#     name = "_no_related_name_%%(class)s_%s" % (no_related_name._next)
#     if hidden:
#         name += '+'
#     return name


# Path: shrubbery/db/extensions/rel_fields.py
from django.db import models as django_models
from shrubbery.db.utils import no_related_name
    from south.modelsinspector import add_introspection_rules



class ForeignRelatedObjectsDescriptor(django_models.fields.related.ForeignRelatedObjectsDescriptor):
    def create_manager(self, instance, superclass):
        field = self.related.field
        superclass = field.related_manager_class or superclass
        cls = super(ForeignRelatedObjectsDescriptor, self).create_manager(instance, superclass)
        if field.related_manager_class_decorator:
            cls = field.related_manager_class_decorator(cls)
        return cls


class ForeignKey(django_models.ForeignKey):
    def __init__(self, *args, **kwargs):
        self.related_manager_class = kwargs.pop('related_manager_class', None)
        self.related_manager_class_decorator = kwargs.pop('related_manager_class_decorator', None)

        if 'related_name' in kwargs and not kwargs['related_name']:
            kwargs['related_name'] = no_related_name()
        super(ForeignKey, self).__init__(*args, **kwargs)

    def contribute_to_related_class(self, cls, related):
        super(ForeignKey, self).contribute_to_related_class(cls, related)
        if self.related_manager_class or self.related_manager_class_decorator:
            setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))


class OneToOneField(django_models.OneToOneField):
    def __init__(self, *args, **kwargs):
        if 'related_name' in kwargs and not kwargs['related_name']:

            kwargs['related_name'] = no_related_name()