Import and return model instance.
964697
def import_model(self, source):
        """"""
        if not hasattr(source, 'read'):  # Not a File-like object
            with open(self._resolve_source(source), 'r') as f:
                return self._import(f)
        else:
            return self._import(source)
1335882
def get(self, model, **spec):
        

        handles = self.__find_handles(model, **spec)
        if len(handles) > 1:
            raise MultipleObjectsReturned()
        if not handles:
            raise ObjectDoesNotExist()
        return self.get_instance(model, handles[0])
78716
def import_model(self, source):
        """"""
        model = super(NonstrictImporter, self).import_model(source)
        sbml.convert_sbml_model(model)
        return model
1325467
def _find_model(self, constructor, table_name, constraints=None, *, columns=None, order_by=None):
    """"""
    data = self.find(table_name, constraints, columns=columns, order_by=order_by)
    return constructor(data) if data else None
469404
def load_model(
            self, the_metamodel, filename, is_main_model, encoding='utf-8',
            add_to_local_models=True):
        

        if not self.local_models.has_model(filename):
            if self.all_models.has_model(filename):
                new_model = self.all_models.filename_to_model[filename]
            else:
                # print("LOADING {}".format(filename))
                # all models loaded here get their references resolved from the
                # root model
                new_model = the_metamodel.internal_model_from_file(
                    filename, pre_ref_resolution_callback=lambda
                    other_model: self.pre_ref_resolution_callback(other_model),
                    is_main_model=is_main_model, encoding=encoding)
                self.all_models.filename_to_model[filename] = new_model
            # print("ADDING {}".format(filename))
            if add_to_local_models:
                self.local_models.filename_to_model[filename] = new_model
        assert self.all_models.has_model(filename)  # to be sure...
        return self.all_models.filename_to_model[filename]
1172376
def _check_model(obj, models=None):
    """"""
    return isinstance(obj, type) and issubclass(obj, pw.Model) and hasattr(obj, '_meta')
286152
async def create(self, model_, **data):
        
        inst = model_(**data)
        query = model_.insert(**dict(inst.__data__))

        pk = await self.execute(query)
        if inst._pk is None:
            inst._pk = pk
        return inst
432947
function StartableModel(model,instance) {
    if(!model) {
        throw new Error('model is required')
    }
    if(!instance) {
        throw new Error('instance is required')
    }
    if(!(this instanceof StartableModel)) {
        return new StartableModel(model,instance,index)
    }
    this.model = model
    this.key = model.key
    this.instance= instance
    this.fn = instance[model.startable]
    if(!this.fn) {
        throw new Error('The instance of ' +
                        this.key +
                        ' does not have a method ' +
                        model.startable +
                       ' which is required for starting this service.')
    }
    this.inject = (this.fn.inject || [])
    this.hasDeps = (this.inject.length > 0)
}
1165936
def prepare_model(self, attrs):
        
        if isinstance(attrs, Model):
            attrs.client = self.client
            attrs.collection = self
            return attrs
        elif isinstance(attrs, dict):
            return self.model(attrs=attrs, client=self.client, collection=self)
        else:
            raise Exception("Can't create %s from %s" %
                            (self.model.__name__, attrs))
157908
def load(self, model):
        
        self.load_medium(model)
        self.load_essentiality(model)
        self.load_growth(model)
        # self.load_experiment(config.config.get("growth"), model)
        return self
387101
def create(cls, data, **kwargs):
        """"""
        with db.session.begin_nested():
            model = cls.dbmodel(**kwargs)
            model.data = data
            obj = cls(model)
            db.session.add(obj.model)
        return obj
136860
def _model_class_from_pk(definition_cls, definition_pk):
    
    try:
        return definition_cls.objects.get(pk=definition_pk).model_class()
    except definition_cls.DoesNotExist:
        pass
432496
def load_object(self, kwargs):
        """"""
        self.object = None
        self.config = None
        self.model = self.get_model_class()
        kwargs.pop('app', None)
        kwargs.pop('model', None)

        if self.model and kwargs.get('pk', False):
            try:
                self.object = self.model.objects.get(pk=kwargs.pop('pk'))
            except Exception:
                raise Exception("Could not load {}".format(self.model.__name__.lower()))
            setattr(self, self.model.__name__.lower(), self.object)

        return kwargs
1017486
def _create(cls, model_class, *args, **kwargs):
        """"""
        if cls._meta.django_get_or_create:
            return cls._get_or_create(model_class, *args, **kwargs)

        manager = cls._get_manager(model_class)
        return manager.create(*args, **kwargs)
791575
def find_or_create(self, constructor, props, *, comp=None):
    
    model = self.find_model(constructor, comp or props)
    if model is None:
      model = constructor(**props)
      self.insert_model(model)
    return model
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
169391
def get_model(self):
        '''
        
        '''
        class Model(object):
            def __init__(self, cnn):
                self.cnn = cnn

        return Model(self.__cnn)