For a related attribute specification, returns (related model,
        attribute).

        Returns (None, None) if model is not found, or (model, None) if
        attribute is not found.
347613
def get_rel_attr(self, attr_name, model):
        
        rel_attr_name, attr_name = attr_name.split(".", 1)
        rel_attr = getattr(self.model, rel_attr_name, None)
        rel_model = None
        attr = None

        if rel_attr is not None:
            rel_model = rel_attr.property.mapper.class_
            attr = getattr(rel_model, attr_name, None)

        return rel_model, attr
267905
def get_related(self):
        
        # Fresh start
        self.related = False
        try:
            for interface in self.interfaces:
                if relation_ids(interface):
                    self.related = True
            return self.related
        except AttributeError as e:
            log("{} {}"
                "".format(self, e), 'INFO')
            return self.related
383584
protected function checkModels($related, $model)
    {
        if (!class_exists($related)) {
            $this->ModelNotFinded($related);
        }
        if (!class_exists(get_class($model))) {
            $this->ModelNotFinded(get_class($model));
        }
    }
564695
def find_related_module(app, related_name):
    """"""

    try:
        app_path = importlib.import_module(app).__path__
    except ImportError as exc:
        warn('Autodiscover: Error importing %s.%s: %r' % (
            app, related_name, exc,
        ))
        return
    except AttributeError:
        return

    try:
        f, _, _ = imp.find_module(related_name, app_path)
        # f is returned None when app_path is a module
        f and f.close()
    except ImportError:
        return

    return importlib.import_module('{0}.{1}'.format(app, related_name))
690304
def session(self, session=None):
        '''
        '''
        if self.related_instance:
            session = self.related_instance.session
        # we have a session, we either create a new one return the same session
        if session is None:
            raise QuerySetError('Related manager can be accessed only from\
 a loaded instance of its related model.')
        return session
666314
def is_models_name_lookup_attribute(self, base):
        
        return (
            isinstance(base, ast.Attribute) and
            isinstance(base.value, ast.Name) and
            base.value.id == 'models' and base.attr == self.model_name_lookup
        )
1192389
def getattribute(model, item):
    
    elements = item.split('.')
    element = elements.pop(0)
    try:
        attr = getattr(model, element, None)
    except:
        return
    if attr is None:  # end of recursion
        return
    if callable(attr):
        try:
            attr = attr()
        except:  # couldn't call this method without params
            return
    if elements:
        return getattribute(attr, '.'.join(elements))
    return attr
23189
def find_or_new(self, id, columns=None):
        
        if columns is None:
            columns = ['*']

        instance = self.find(id, columns)

        if instance is None:
            instance = self._related.new_instance()
            self._set_foreign_attributes_for_create(instance)

        return instance
373292
def _related_items_changed(self, **kwargs):
        
        for_model = kwargs["instance"].content_type.model_class()
        if for_model and issubclass(for_model, self.model):
            instance_id = kwargs["instance"].object_pk
            try:
                instance = for_model.objects.get(id=instance_id)
            except self.model.DoesNotExist:
                # Instance itself was deleted - signals are irrelevant.
                return
            if hasattr(instance, "get_content_model"):
                instance = instance.get_content_model()
            related_manager = getattr(instance, self.related_field_name)
            self.related_items_changed(instance, related_manager)
1191938
def _get_has_relation_query(self, relation):
        
        from .relations import Relation

        return Relation.no_constraints(
            lambda: getattr(self.get_model(), relation)()
        )
276200
def _get_extension_by_related_name(self, related_name):
        
        if related_name is None:
            return self._extensions[0]

        for meta in self._extensions:
            if meta.rel_name == related_name:
                return meta

        raise ValueError("No translated model of '{0}' has a reverse name of '{1}'".format(
            self.root.shared_model.__name__, related_name
        ))
777321
def get_object_or_none(model, *args, **kwargs):
    
    try:
        return model._default_manager.get(*args, **kwargs)
    except model.DoesNotExist:
        return None
611794
def for_model(self, model, content_type=None):
        '''  '''
        content_type = content_type or ContentType.objects.get_for_model(model)
        kwargs = {
                    self.ct_field: content_type,
                    self.fk_field: model.pk
                 }
        objects = self.get_query_set().filter(**kwargs)
        return objects
873151
def get_model_field(schema, field):
    
    if schema._declared_fields.get(field) is None:
        raise Exception("{} has no attribute {}".format(schema.__name__, field))

    if schema._declared_fields[field].attribute is not None:
        return schema._declared_fields[field].attribute
    return field
75172
def check_model_cls(attributes):
        
        model_cls = attributes.get('__model_cls__')
        if model_cls is None:
            raise AttributeError("Attribute __model_cls__ is required.")

        if not issubclass(model_cls, models.DomainModel):
            raise TypeError("Attribute __model_cls__ must be subclass of "
                            "DomainModel.")
221466
def get_model(self):
        
        if hasattr(self, 'model') and self.model:
            return self.model
        # Give me a "none" queryset
        try:
            none = self.get_queryset().none()
            return none.model
        except Exception:
            raise ImproperlyConfigured(
                "Integrator: Unable to determine the model with this queryset."
                " Please add a `model` property")
162628
def value(self):
        
        if self.filter_.get('field') is not None:
            try:
                result = getattr(self.model, self.filter_['field'])
            except AttributeError:
                raise InvalidFilters("{} has no attribute {}".format(self.model.__name__, self.filter_['field']))
            else:
                return result
        else:
            if 'val' not in self.filter_:
                raise InvalidFilters("Can't find value or field in a filter")

            return self.filter_['val']