Internal Django method to associate the field with the Model; it assigns the descriptor.
493818
def contribute_to_class(self, cls, name, **kwargs):
        
        super(PlaceholderField, self).contribute_to_class(cls, name, **kwargs)

        # overwrites what instance.<colname> returns; give direct access to the placeholder
        setattr(cls, name, PlaceholderFieldDescriptor(self.slot))

        # Make placeholder fields easy to find
        # Can't assign this to cls._meta because that gets overwritten by every level of model inheritance.
        if not hasattr(cls, '_meta_placeholder_fields'):
            cls._meta_placeholder_fields = {}
        cls._meta_placeholder_fields[name] = self

        # Configure the revere relation if possible.
        # TODO: make sure reverse queries work properly
        if django.VERSION >= (1, 11):
            rel = self.remote_field
        else:
            rel = self.rel

        if rel.related_name is None:
            # Make unique for model (multiple models can use same slotnane)
            rel.related_name = '{app}_{model}_{slot}_FIXME'.format(
                app=cls._meta.app_label,
                model=cls._meta.object_name.lower(),
                slot=self.slot
            )

            # Remove attribute must exist for the delete page. Currently it's not actively used.
            # The regular ForeignKey assigns a ForeignRelatedObjectsDescriptor to it for example.
            # In this case, the PlaceholderRelation is already the reverse relation.
            # Being able to move forward from the Placeholder to the derived models does not have that much value.
            setattr(rel.to, self.rel.related_name, None)
1021035
def describe_field(field_definition):
    
    field_descriptor = FieldDescriptor()
    field_descriptor.name = field_definition.name
    field_descriptor.number = field_definition.number
    field_descriptor.variant = field_definition.variant

    if isinstance(field_definition, messages.EnumField):
        field_descriptor.type_name = field_definition.type.definition_name()

    if isinstance(field_definition, messages.MessageField):
        field_descriptor.type_name = (
            field_definition.message_type.definition_name())

    if field_definition.default is not None:
        field_descriptor.default_value = _DEFAULT_TO_STRING_MAP[
            type(field_definition)](field_definition.default)

    # Set label.
    if field_definition.repeated:
        field_descriptor.label = FieldDescriptor.Label.REPEATED
    elif field_definition.required:
        field_descriptor.label = FieldDescriptor.Label.REQUIRED
    else:
        field_descriptor.label = FieldDescriptor.Label.OPTIONAL

    return field_descriptor
1255171
def _init_field(self, setting, field_class, name, code=None):
        
        kwargs = {
            "label": setting["label"] + ":",
            "required": setting["type"] in (int, float),
            "initial": getattr(settings, name),
            "help_text": self.format_help(setting["description"]),
        }
        if setting["choices"]:
            field_class = forms.ChoiceField
            kwargs["choices"] = setting["choices"]
        field_instance = field_class(**kwargs)
        code_name = ('_modeltranslation_' + code if code else '')
        self.fields[name + code_name] = field_instance
        css_class = field_class.__name__.lower()
        field_instance.widget.attrs["class"] = css_class
        if code:
            field_instance.widget.attrs["class"] += " modeltranslation"
46938
def update_model(self, model):
        
        for k, v in self.parse_form().items():
            setattr(model, k, v)
1288661
def associate(self, model):
        
        self._parent.set_attribute(self._foreign_key, model.get_attribute(self._other_key))

        return self._parent.set_relation(self._relation, model)
1342413
def initialize_fields(self):
        
        for field in dir(self):
            obj = getattr(self, field)
            if isinstance(obj, Field):
                self._meta.fields[field] = obj
90698
def add_model(self, model):
        
        if model.identity not in self._models.keys():
            self._models[model.identity] = model
        else:
            raise ValueError("{} has already been defined".format(model.identity))
609195
def set_model(self, model):
        
        if self.model:
            self.model.unregister_observer(self)
        self.model = model
        if self.model:
            self.model.register_observer(self)
            self.model_notification()
        else:
            self.set_widget(None)
        self.widget.set_sensitive(bool(self.model))
823947
def add_field(self, descriptor):
        
        self.__current_descriptor.setdefault('fields', [])
        self.__current_descriptor['fields'].append(descriptor)
        self.__build()
        return self.__fields[-1]
941251
def django_field_to_index(field, **attr):
    '''
    
    '''

    dj_type = field.get_internal_type()

    if dj_type in ('DateField', 'DateTimeField'):
        return DateField(**attr)
    elif dj_type in ('BooleanField', 'NullBooleanField'):
        return BooleanField(**attr)
    elif dj_type in ('DecimalField', 'FloatField'):
        return NumberField(coretype='float', **attr)
    elif dj_type in ('PositiveSmallIntegerField', 'SmallIntegerField'):
        return NumberField(coretype='short', **attr)
    elif dj_type in ('IntegerField', 'PositiveIntegerField', 'AutoField'):
        return NumberField(coretype='integer', **attr)
    elif dj_type in ('BigIntegerField'):
        return NumberField(coretype='long', **attr)

    return StringField(**attr)
60598
def init_self(self, cls, name):
        
        # the class the descriptor is defined on
        self.this_class = cls
        # the attribute name of this descriptor
        self.this_name = name
372946
def add_to_class(self, model_class):
        
        model_class._meta.add_field(self)
        setattr(model_class, self.name, _FieldDescriptor(self))
1314846
public void assignField(ConnectionSource connectionSource, Object data, Object val, boolean parentObject,
			ObjectCache objectCache) throws SQLException {

		if (logger.isLevelEnabled(Level.TRACE)) {
			logger.trace("assiging from data {}, val {}: {}", (data == null ? "null" : data.getClass()),
					(val == null ? "null" : val.getClass()), val);
		}
		// if this is a foreign object then val is the foreign object's id val
		if (foreignRefField != null && val != null) {
			// get the current field value which is the foreign-id
			Object foreignRef = extractJavaFieldValue(data);
			/*
			 * See if we don't need to create a new foreign object. If we are refreshing and the id field has not
			 * changed then there is no need to create a new foreign object and maybe lose previously refreshed field
			 * information.
			 */
			if (foreignRef != null && foreignRef.equals(val)) {
				return;
			}
			// awhitlock: raised as OrmLite issue: bug #122
			Object cachedVal;
			ObjectCache foreignCache = foreignDao.getObjectCache();
			if (foreignCache == null) {
				cachedVal = null;
			} else {
				cachedVal = foreignCache.get(getType(), val);
			}
			if (cachedVal != null) {
				val = cachedVal;
			} else if (!parentObject) {
				// the value we are to assign to our field is now the foreign object itself
				val = createForeignObject(connectionSource, val, objectCache);
			}
		}

		if (fieldSetMethod == null) {
			try {
				field.set(data, val);
			} catch (IllegalArgumentException e) {
				if (val == null) {
					throw SqlExceptionUtil.create("Could not assign object '" + val + "' to field " + this, e);
				} else {
					throw SqlExceptionUtil.create(
							"Could not assign object '" + val + "' of type " + val.getClass() + " to field " + this, e);
				}
			} catch (IllegalAccessException e) {
				throw SqlExceptionUtil.create(
						"Could not assign object '" + val + "' of type " + val.getClass() + "' to field " + this, e);
			}
		} else {
			try {
				fieldSetMethod.invoke(data, val);
			} catch (Exception e) {
				throw SqlExceptionUtil
						.create("Could not call " + fieldSetMethod + " on object with '" + val + "' for " + this, e);
			}
		}
	}
1309468
def get_class_field(cls, field_name):
        
        if not cls.has_field(field_name):
            raise AttributeError('"%s" is not a field for the model "%s"' %
                                 (field_name, cls.__name__))

        field = getattr(cls, '_redis_attr_%s' % field_name)

        return field
1170951
def set_context(self, serializer):
        
        # Determine the underlying model field names. These may not be the
        # same as the serializer field names if `source=<>` is set.
        self.field_name = serializer.fields[self.field].source_attrs[0]
        self.date_field_name = serializer.fields[self.date_field].source_attrs[0]
        # Determine the existing instance, if this is an update operation.
        self.instance = getattr(serializer, 'instance', None)
1170104
def set_field(self, name, value):
        """"""
        f = getattr(self, name, None)
        if isinstance(f, DataField):
            f.set(self, value)
        else:
            raise FieldError("No field named '%s'" % name)
1073095
def add_field(cls, name, descriptor):
        
        if not isinstance(descriptor, MediaField):
            raise ValueError(
                u'{0} must be an instance of MediaField'.format(descriptor))
        if name in cls.__dict__:
            raise ValueError(
                u'property "{0}" already exists on MediaField'.format(name))
        setattr(cls, name, descriptor)