'Determine the relationship between this model and related_model.
related_model must have some sort of many-valued relationship to this
manager\'s model.
:return: (relationship_type, field), where relationship_type is one of
MANY_TO_ONE, M2M_ON_RELATED_MODEL, M2M_ON_THIS_MODEL, and field
is the Django field object for the relationship.'

def determine_relationship(self, related_model):

    for field in related_model._meta.fields:
        if self._is_relation_to(field, self.model):
            return (self.MANY_TO_ONE, field)
    for field in related_model._meta.many_to_many:
        if self._is_relation_to(field, self.model):
            return (self.M2M_ON_RELATED_MODEL, field)
    for field in self.model._meta.many_to_many:
        if self._is_relation_to(field, related_model):
            return (self.M2M_ON_THIS_MODEL, field)
    raise ValueError(('%s    has    no    relation    to    %s' % (related_model, self.model)))
