# 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
        if hasattr(manager, 'assign'):
            manager.assign(value)
        else:
            manager.clear()
            manager.add(*value)


class ManyToManyField(django_models.ManyToManyField):
    def __init__(self, *args, **kwargs):
        self.manager_class = kwargs.pop('manager_class', None)
        self.manager_class_decorator = kwargs.pop('manager_class_decorator', None)
        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(ManyToManyField, self).__init__(*args, **kwargs)

    def contribute_to_class(self, cls, name):
        super(ManyToManyField, self).contribute_to_class(cls, name)
        if self.manager_class or self.manager_class_decorator:
            descr = ManyToManyDescriptor(self,
                lambda: self.rel.to,
                lambda: self.m2m_field_name(),
                lambda: self.m2m_reverse_field_name(), self.related_query_name,
                self.manager_class, self.manager_class_decorator)
            setattr(cls, self.name, descr)

    def contribute_to_related_class(self, cls, related):

# 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

        if hasattr(manager, 'assign'):
            manager.assign(value)
        else:
            manager.clear()
            manager.add(*value)


class ManyToManyField(django_models.ManyToManyField):
    def __init__(self, *args, **kwargs):
        self.manager_class = kwargs.pop('manager_class', None)
        self.manager_class_decorator = kwargs.pop('manager_class_decorator', None)
        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(ManyToManyField, self).__init__(*args, **kwargs)

    def contribute_to_class(self, cls, name):
        super(ManyToManyField, self).contribute_to_class(cls, name)
        if self.manager_class or self.manager_class_decorator:
            descr = ManyToManyDescriptor(self,
                lambda: self.rel.to,
                lambda: self.m2m_field_name(),
                lambda: self.m2m_reverse_field_name(), self.related_query_name,
                self.manager_class, self.manager_class_decorator)
            setattr(cls, self.name, descr)

    def contribute_to_related_class(self, cls, related):

        super(ManyToManyField, self).contribute_to_related_class(cls, related)