Init model with field.

        :param DomainModel model:
        :param object value:
324642
def init_model(self, model, value):
        
        if value is None and self.default is not None:
            value = self.default() if callable(self.default) else self.default

        self.set_value(model, value)
536125
function Model(attributes, options) {
  var _attributes = attributes || {};
  options = options || {};
  this.attributes = Object.create(null);
  this.set(_attributes, options);
  this.initialize.apply(this, arguments);
}
521059
def _initialize(self):
        
        meta = getattr(self, ModelBase._meta_attr)
        # read modelfile, convert JSON and load/update model
        if self.param_file is not None:
            self._load()
        LOGGER.debug('model:\n%r', self.model)
        # initialize layers
        # FIXME: move import inside loop for custom layers in different modules
        mod = importlib.import_module(meta.layers_mod, meta.layers_pkg)
        src_model = {}
        for layer, value in self.model.iteritems():
            # from layers module get the layer's class definition
            layer_cls = getattr(mod, meta.layer_cls_names[layer])  # class def
            self.layers[layer] = layer_cls  # add layer class def to model
            # check if model layers are classes
            src_value = {}  # layer value generated from source classes
            for src in value['sources']:
                # check if source has keyword arguments
                try:
                    src, kwargs = src
                except (TypeError, ValueError):
                    kwargs = {}  # no key work arguments
                # skip if not a source class
                if isinstance(src, basestring):
                    continue
                # generate layer value from source class
                src_value[src.__name__] = {'module': src.__module__,
                                           'package': None}
                # update layer keyword arguments
                src_value[src.__name__].update(kwargs)
            # use layer values generated from source class
            if src_value:
                value = src_model[layer] = src_value
            else:
                srcmod, srcpkg = value.get('module'), value.get('package')
                try:
                    value = dict(value['sources'])
                except ValueError:
                    value = dict.fromkeys(value['sources'], {})
                for src in value.viewkeys():
                    if srcmod is not None:
                        value[src]['module'] = srcmod
                    if srcpkg is not None:
                        value[src]['package'] = srcpkg
            # set layer attribute with model data
            setattr(self, layer, layer_cls(value))
        # update model with layer values generated from source classes
        if src_model:
            self.model.update(src_model)
        self._update()
        self._state = 'initialized'
457820
def initialize_post(self):
        
        self.model = self.get_model()
        for key in self.model.keys():
            self.model.set(key, self.json_arguments.get(key))
744426
def create_attribute_model(self, initial_value=None):
        # type: (Any) -> AttributeModel
        
        attr = self.attribute_class(meta=self, value=initial_value)
        return attr
181806
public void init(BaseField field, BaseField fldDest, BaseField fldSource)
    {
        super.init(field, fldDest, fldSource, false, false, false);
    }
779150
def setModel(self, model):
        

        LOGGER.debug("> Setting '{0}' model.".format(model))

        if not model:
            return

        umbra.ui.views.Abstract_QTreeView.setModel(self, model)
1320247
def construct(cls: Type['Model'], values: 'DictAny', fields_set: 'SetStr') -> 'Model':
        
        m = cls.__new__(cls)
        object.__setattr__(m, '__values__', values)
        object.__setattr__(m, '__fields_set__', fields_set)
        return m
1283911
private void populateModel()
   {
      if (m_count != 0)
      {
         m_count = 0;
         Arrays.fill(m_flags, false);
      }

      for (Resource resource : m_parentFile.getResources())
      {
         for (int loop = 0; loop < MPXResourceField.MAX_FIELDS; loop++)
         {
            if (resource.getCachedValue(MPXResourceField.getMpxjField(loop)) != null)
            {
               if (m_flags[loop] == false)
               {
                  m_flags[loop] = true;
                  m_fields[m_count] = loop;
                  ++m_count;
               }
            }
         }
      }

      //
      // Ensure the the model fields always appear in the same order
      //
      Arrays.sort(m_fields);
      System.arraycopy(m_fields, m_fields.length - m_count, m_fields, 0, m_count);
   }
1346333
public void init(BaseMessageReceiver messageReceiver, AbstractTableModel model)
    {
        super.init(messageReceiver, null);
        m_model = model;
    }
87394
def create_values(self, base_model=models.Model, base_manager=models.Manager):
        

        _builder = self

        class CustomContentTypeFieldValueManager(base_manager):
            def create(self, **kwargs):
                """
                Subclass create in order to be able to use "value" in kwargs
                instead of using "value_%s" passing also type directly
                """
                if 'value' in kwargs:
                    value = kwargs.pop('value')
                    created_object = super(CustomContentTypeFieldValueManager, self).create(**kwargs)
                    created_object.value = value
                    return created_object
                else:
                    return super(CustomContentTypeFieldValueManager, self).create(**kwargs)

        @python_2_unicode_compatible
        class CustomContentTypeFieldValue(base_model):
            custom_field = models.ForeignKey('.'.join(_builder.fields_model),
                                             verbose_name=_('custom field'),
                                             related_name='+')
            content_type = models.ForeignKey(ContentType, editable=False,
                                             verbose_name=_('content type'),
                                             limit_choices_to=_builder.content_types_query)
            object_id = models.PositiveIntegerField(_('object id'), db_index=True)
            content_object = GenericForeignKey('content_type', 'object_id')

            value_text = models.TextField(blank=True, null=True)
            value_integer = models.IntegerField(blank=True, null=True)
            value_float = models.FloatField(blank=True, null=True)
            value_time = models.TimeField(blank=True, null=True)
            value_date = models.DateField(blank=True, null=True)
            value_datetime = models.DateTimeField(blank=True, null=True)
            value_boolean = models.NullBooleanField(blank=True)

            objects = CustomContentTypeFieldValueManager()

            def _get_value(self):
                return getattr(self, 'value_%s' % self.custom_field.data_type)

            def _set_value(self, new_value):
                setattr(self, 'value_%s' % self.custom_field.data_type, new_value)

            value = property(_get_value, _set_value)

            class Meta:
                unique_together = ('custom_field', 'content_type', 'object_id')
                verbose_name = _('custom field value')
                verbose_name_plural = _('custom field values')
                abstract = True

            def save(self, *args, **kwargs):
                # save content type as user shouldn't be able to change it
                self.content_type = self.custom_field.content_type
                super(CustomContentTypeFieldValue, self).save(*args, **kwargs)

            def validate_unique(self, exclude=None):
                qs = self.__class__._default_manager.filter(
                    custom_field=self.custom_field,
                    content_type=self.custom_field.content_type,
                    object_id=self.object_id,
                )
                if not self._state.adding and self.pk is not None:
                    qs = qs.exclude(pk=self.pk)
                if qs.exists():
                    raise ValidationError({ NON_FIELD_ERRORS: (_('A value for this custom field already exists'),) })

            def __str__(self):
                return "%s: %s" % (self.custom_field.name, self.value)

        return CustomContentTypeFieldValue
234421
def create(self, fields):
        
        try:
            # Cleaning the fields, and check if has `ForeignKey` type.
            cleaned_fields = {}
            for key, value in fields.items():
                if type(value) is dict:
                    try:
                        if value['type'] == 'fk':
                            fake_fk = self.fake_fk(value['field_name'])
                            cleaned_fields.update({key: fake_fk})
                    except:
                        pass
                else:
                    cleaned_fields.update({key: value})

            # Creating the object from dictionary fields.
            model_class = self.model_class()
            obj = model_class.objects.create(**cleaned_fields)

            # The `ManyToManyField` need specific object,
            # so i handle it after created the object.
            for key, value in fields.items():
                if type(value) is dict:
                    try:
                        if value['type'] == 'm2m':
                            self.fake_m2m(obj, value['field_name'])
                    except:
                        pass
            try:
                obj.save_m2m()
            except:
                obj.save()
            return obj
        except Exception as e:
            raise e
599171
def init_object(self, args, kwargs):
        
        self.object_id = kwargs.pop(self.pk, None)
        if self.object_id is not None:
            self.obj = self.Model.query.get(self.object_id)
            actions.context["object"] = self.obj

        return args, kwargs
296244
def initialize(self, training_info, model, environment, device):
        
        if self.trust_region:
            self.average_model = self.model_factory.instantiate(action_space=environment.action_space).to(device)
            self.average_model.load_state_dict(model.state_dict())
586352
def set_model(self, m):
        
        self._model = m
        self.new_root.emit(QtCore.QModelIndex())
        self.model_changed(m)
342993
def __initialize_model(self):
        

        LOGGER.debug("> Initializing model.")

        self.beginResetModel()
        self.root_node = umbra.ui.nodes.DefaultNode(name="InvisibleRootNode")
        self.__default_project_node = ProjectNode(name=self.__default_project,
                                                  parent=self.root_node,
                                                  node_flags=int(Qt.ItemIsEnabled),
                                                  attributes_flags=int(Qt.ItemIsEnabled))
        self.enable_model_triggers(True)
        self.endResetModel()
1192819
def initialize_fields(self):
        
        # # Pull all the "normal" fields off the model instance meta.
        for name, field in self.instance._meta.fields.items():
            if getattr(field, 'primary_key', False):
                continue
            self._meta.fields[name] = self.convert_field(name, field)

        # Many-to-many fields are not stored in the meta fields dict.
        # Pull them directly off the class.
        for name in dir(type(self.instance)):
            field = getattr(type(self.instance), name, None)
            if isinstance(field, ManyToManyField):
                self._meta.fields[name] = self.convert_field(name, field)

        super().initialize_fields()