See docs for `Model` abstract base class.
160630
def branchScale(self):
        """"""
        bs = -(self.Phi_x * scipy.diagonal(self.Pxy[0])).sum() * self.mu
        assert bs > 0
        return bs
731470
def from_es(self, hit):
        """"""
        doc = hit.copy()
        klass = shallow_class_factory(self.model)

        # We can pass in the entire source, except when we have a non-indexable many-to-many
        for field in self.model._meta.get_fields():

            if not field.auto_created and field.many_to_many:
                if not issubclass(field.rel.to, Indexable):
                    if field.name in doc["_source"]:
                        del doc["_source"][field.name]

            # if field.one_to_many:
            #     if field.name in doc["_source"]:
            #         del doc["_source"][field.name]

        # Now let's go ahead and parse all the fields
        fields = self.mapping.properties.properties
        for key in fields:
            # TODO: What if we've mapped the property to a different name? Will we allow that?
            field = fields[key]

            # if isinstance(field, InnerObject):
            #     import pdb; pdb.set_trace()
            #     continue

            if doc["_source"].get(key):
                attribute_value = doc["_source"][key]

                doc["_source"][key] = field.to_python(attribute_value)

        return klass(**doc["_source"])
1316018
def _use_for_model(self, model):
        
        original_database = getattr(model, 'database', None)

        def get_models(model):
            """
            Return the model and all its submodels that are on the same database
            """
            model_database = getattr(model, 'database', None)
            if model_database == self:
                return []
            models = [model]
            for submodel in model.__subclasses__():
                if getattr(submodel, 'database', None) == model_database:
                    models += get_models(submodel)
            return models

        # put the model and all its matching submodels on the new database
        models = get_models(model)
        for _model in models:
            if not _model.abstract:
                self._add_model(_model)
                del original_database._models[_model._name]
            _model.database = self

        # return updated models
        return models
1072202
def get_value(self, meta, base_model_meta, mcs_args: McsArgs):
        """"""
        if mcs_args.Meta.abstract:
            return None
        value = getattr(base_model_meta, self.name, {}) or {}
        value.update(getattr(meta, self.name, {}))
        return value
320958
def models_descriptive(self):
        
        f = self._parent
        return {name: {a: f[name].attrs[a]
                       for a in H5File.stored_attributes}
                for name in f.keys()}
271711
def as_models(self, klass):
        """"""
        try:
            return [klass(mod) for mod in self.tree.reply.data.results.array[0].item]
        except AttributeError:
            return []
33407
def bind_model_cls(self, model_cls):
        """"""
        if self.model_cls:
            raise errors.Error('"{0}" has been already bound to "{1}" and '
                               'could not be rebound to "{2}"'.format(
                                   self, self.model_cls, model_cls))
        self.model_cls = model_cls
        return self
208041
def modelresource_factory(model, resource_class=ModelResource):
    
    attrs = {'model': model}
    Meta = type(str('Meta'), (object,), attrs)

    class_name = model.__name__ + str('Resource')

    class_attrs = {
        'Meta': Meta,
    }

    metaclass = ModelDeclarativeMetaclass
    return metaclass(class_name, (resource_class,), class_attrs)
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
1253047
def register_model(cls: Type[Model]):
    
    if not issubclass(cls, Model):
        raise TypeError("model bust be a subclass of Model")
    if issubclass(cls, GenericModel):
        raise TypeError("model must not be a subclass of GenericModel")
    __models__.add(cls)
    return cls
727037
def _initialize_references(model_class, name, bases, attrs):
    """"""
    model_class._references = {}
    h = {}
    deferred = []
    for k, v in attrs.iteritems():
        if isinstance(v, ReferenceField):
            model_class._references[k] = v
            v.name = v.name or k
            att = Attribute(name=v.attname)
            h[v.attname] = att
            setattr(model_class, v.attname, att)
            refd = _initialize_referenced(model_class, v)
            if refd:
                deferred.append(refd)
    attrs.update(h)
    return deferred
1374993
def get_fieldsets(self, request, obj=None):
        '''  '''
        # If subclass declares fieldsets, this is respected
        if (hasattr(self, 'declared_fieldset') and self.declared_fieldsets) \
           or not self.base_fieldsets:
            return super(PolymorphicChildModelAdmin, self).get_fieldsets(request, obj)

        other_fields = self.get_subclass_fields(request, obj)

        if other_fields:
            return (
                (self.extra_fieldset_title, {'fields': other_fields}),
            ) + self.base_fieldsets
        else:
            return self.base_fieldsets
414738
def get_model(model, ctx, opt):
    """"""
    kwargs = {'ctx': ctx, 'pretrained': opt.use_pretrained, 'classes': classes}
    if model.startswith('resnet'):
        kwargs['thumbnail'] = opt.use_thumbnail
    elif model.startswith('vgg'):
        kwargs['batch_norm'] = opt.batch_norm

    net = models.get_model(model, **kwargs)
    if opt.resume:
        net.load_parameters(opt.resume)
    elif not opt.use_pretrained:
        if model in ['alexnet']:
            net.initialize(mx.init.Normal())
        else:
            net.initialize(mx.init.Xavier(magnitude=2))
    net.cast(opt.dtype)
    return net
416650
def inline_for_model(model, variants=[], inline_args={}):
    

    if not isinstance(model, ModelBase):
        raise ValueError("inline_for_model requires it's argument to be a Django Model")
    d = dict(model=model)
    if variants:
        d['variants'] = variants
    if inline_args:
        d['args'] = inline_args
    class_name = "%sInline" % model._meta.module_name.capitalize()
    return type(class_name, (ModelInline,), d)
392833
def _get_inherited_field_types(class_to_field_type_overrides, schema_graph):
    """"""
    inherited_field_type_overrides = dict()
    for superclass_name, field_type_overrides in class_to_field_type_overrides.items():
        for subclass_name in schema_graph.get_subclass_set(superclass_name):
            inherited_field_type_overrides.setdefault(subclass_name, dict())
            inherited_field_type_overrides[subclass_name].update(field_type_overrides)
    return inherited_field_type_overrides
123494
def resolve_model(self, model):
        '''
        
        '''
        if not model:
            raise ValueError('Unsupported model specifications')
        if isinstance(model, basestring):
            classname = model
        elif isinstance(model, dict) and 'class' in model:
            classname = model['class']
        else:
            raise ValueError('Unsupported model specifications')

        try:
            return get_document(classname)
        except self.NotRegistered:
            message = 'Model "{0}" does not exist'.format(classname)
            raise ValueError(message)
913118
def load_model_from_package(name, **overrides):
    """"""
    cls = importlib.import_module(name)
    return cls.load(**overrides)