Attach the current field to an instance of a model. Can be overriden to
        do something when an instance is set
486712
def _attach_to_instance(self, instance):
        
        self._instance = instance
        self.lockable = self.lockable and instance.lockable
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)
617242
def model_setattr():
    

    def model_setattr(value, context, **_params):
        setattr(context["model"], context["key"], value)
        return _attr()

    return model_setattr
1264214
def _bind_to_schema(self, field_name, schema):
        
        self.parent = self.parent or schema
        self.name = self.name or field_name
823947
def add_field(self, descriptor):
        
        self.__current_descriptor.setdefault('fields', [])
        self.__current_descriptor['fields'].append(descriptor)
        self.__build()
        return self.__fields[-1]
547643
def _add_dynamic_field_to_instance(self, field, field_name):
        
        # create the new field
        new_field = field._create_dynamic_version()
        new_field.name = field_name
        new_field._attach_to_instance(self)

        # add the field to the list to avoid doing all of this again
        if field_name not in self._fields:  # (maybe already in it via the class)
            if id(self._fields) == id(self.__class__._fields):
                # unlink the list from the class
                self._fields = list(self._fields)
            self._fields.append(field_name)

        # if the field is an hashable field, add it to the list to allow calling
        # hmget on these fields
        if isinstance(field, limpyd_fields.InstanceHashField):
            if id(self._instancehash_fields) == id(self.__class__._instancehash_fields):
                # unlink the link from the class
                self._instancehash_fields = list(self._instancehash_fields)
            self._instancehash_fields.append(field_name)

        # set it as an attribute on the instance, to be reachable
        setattr(self, field_name, new_field)

        return new_field
412639
private static void setField(final Object instance, final Field field, final Object value)
   {
      final boolean accessability = field.isAccessible();

      try
      {
         field.setAccessible(true);
         field.set(instance, value);
      }
      catch (Exception e)
      {
         InjectionException.rethrow(e);
      }
      finally
      {
         field.setAccessible(accessability);
      }
   }
1153166
def attach(self):
        
        log_recording = LogRecording(parent_object_id=self.parent_object_id, created_at=datetime.utcnow())
        self.log_recording_dao.remove(self.parent_object_id)
        self.log_recording_dao.update(log_recording)

        formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s',
                                      datefmt='%Y-%m-%d %H:%M:%S')
        self.setFormatter(formatter)
        self.logger.addHandler(self)
1258523
def attach(object, name):
    
    def decorator(func):
        setattr(object, name, func)
        return func
    return decorator
907048
def _bind_field(self, field_name, field_obj):
        
        try:
            if field_name in self.load_only:
                field_obj.load_only = True
            if field_name in self.dump_only:
                field_obj.dump_only = True
            field_obj._bind_to_schema(field_name, self)
            self.on_bind_field(field_name, field_obj)
        except TypeError:
            # field declared as a class, not an instance
            if (isinstance(field_obj, type) and
                    issubclass(field_obj, base.FieldABC)):
                msg = ('Field for "{}" must be declared as a '
                       'Field instance, not a class. '
                       'Did you mean "fields.{}()"?'
                       .format(field_name, field_obj.__name__))
                raise TypeError(msg)
375481
def _add_dynamic_field_to_model(cls, field, field_name):
        
        # create the new field
        new_field = field._create_dynamic_version()
        new_field.name = field_name
        new_field._attach_to_model(cls)

        # set it as an attribute on the class, to be reachable
        setattr(cls, "_redis_attr_%s" % field_name, new_field)

        # NOTE: don't add the field to the "_fields" list, to avoid use extra
        #       memory to each future instance that will create a field for each
        #       dynamic one created

        # # add the field to the list to avoid to done all of this again
        # # (_fields is already on this class only, not subclasses)
        # cls._fields.append(field_name)

        # each subclass needs its own copy
        for subclass in cls.__subclasses__():
            subclass._add_dynamic_field_to_model(field, field_name)

        return new_field
946542
def field(name, *params)
      @model.translated_attribute_names.push name.to_sym
      @model.translated_attr_accessor(name)
      @model.translation_class.field name, *params
    end
258683
def bind(self, field_name, parent):
        
        super(TranslatedFieldsField, self).bind(field_name, parent)

        # Expect 1-on-1 for now. Allow using source as alias,
        # but it should not be a dotted path for now
        related_name = self.source or field_name

        # This could all be done in __init__(), but by moving the code here,
        # it's possible to auto-detect the parent model.
        if self.shared_model is not None and self.serializer_class is not None:
            return

        # Fill in the blanks
        if self.serializer_class is None:
            if self.shared_model is None:
                # Auto detect parent model
                from .serializers import TranslatableModelSerializer
                if not isinstance(parent, TranslatableModelSerializer):
                    raise TypeError("Expected 'TranslatableModelSerializer' as serializer base class")
                if not issubclass(parent.Meta.model, TranslatableModel):
                    raise TypeError("Expected 'TranslatableModel' for the parent model")

                self.shared_model = parent.Meta.model

            # Create serializer based on shared model.
            translated_model = self.shared_model._parler_meta[related_name]
            self.serializer_class = create_translated_fields_serializer(
                self.shared_model, related_name=related_name,
                meta={'fields': translated_model.get_translated_fields()}
            )
        else:
            if not issubclass(self.serializer_class.Meta.model, TranslatedFieldsModel):
                raise TypeError("Expected 'TranslatedFieldsModel' for the serializer model")
389352
def set_value_field(self, model, field_name):
        
        fields = fields_for_model(model, fields=[field_name])
        self.fields['value'] = fields[field_name]
983208
def bind(self, *args, **kwargs):
        """"""
        if self.bound:  # Prevent double-binding
            return
        super(DynamicRelationField, self).bind(*args, **kwargs)
        self.bound = True
        parent_model = getattr(self.parent.Meta, 'model', None)

        remote = is_field_remote(parent_model, self.source)

        try:
            model_field = get_model_field(parent_model, self.source)
        except:
            # model field may not be available for m2o fields with no
            # related_name
            model_field = None

        # Infer `required` and `allow_null`
        if 'required' not in self.kwargs and (
                remote or (
                    model_field and (
                        model_field.has_default() or model_field.null
                    )
                )
        ):
            self.required = False
        if 'allow_null' not in self.kwargs and getattr(
                model_field, 'null', False
        ):
            self.allow_null = True

        self.model_field = model_field
23612
def attached_to_model(self):
        """"""
        try:
            if not bool(self.model):
                return False
        except AttributeError:
            return False
        else:
            try:
                return not bool(self.instance)
            except AttributeError:
                return True
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