Add this :class:`Field` to the fields of :attr:`model`.
773300
def add_to_fields(self):
        ''''''
        meta = self.model._meta
        meta.scalarfields.append(self)
        if self.index:
            meta.indices.append(self)
573542
def add_attr2fields(self, attr_name, attr_val, fields=[], exclude=[], include_all_if_empty=True):
        
        for f in self.filter_fields(fields, exclude, include_all_if_empty):
            f = self.fields[f.name]
            org_val = f.widget.attrs.get(attr_name, '')
            f.widget.attrs[attr_name] = '%s %s' % (org_val, attr_val) if org_val else attr_val
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
333169
def model_fields(model, allow_pk=False, only=None, exclude=None,
                 field_args=None, converter=None):
    
    converter = converter or ModelConverter()
    field_args = field_args or {}

    model_fields = list(model._meta.sorted_fields)
    if not allow_pk:
        model_fields.pop(0)

    if only:
        model_fields = [x for x in model_fields if x.name in only]
    elif exclude:
        model_fields = [x for x in model_fields if x.name not in exclude]

    field_dict = {}
    for model_field in model_fields:
        name, field = converter.convert(
            model,
            model_field,
            field_args.get(model_field.name))
        field_dict[name] = field

    return field_dict
551259
def _django_to_es_field(self, field):
        """"""
        from django.db import models

        prefix = ""
        if field.startswith("-"):
            prefix = "-"
            field = field.lstrip("-")

        if field in ["id", "pk"]:
            return "_id", models.AutoField

        try:
            dj_field, _, _, _ = self.model._meta.get_field_by_name(field)
            if isinstance(dj_field, models.ForeignKey):
                return prefix + field + "_id", models.ForeignKey
            else:
                return prefix + field, dj_field
        except models.FieldDoesNotExist:
            pass

        return prefix + field.replace(FIELD_SEPARATOR, "."), None
154780
def before_add_field(self, field):
        
        if self.extract_fields and field.name == '*':
            field.ignore = True
            fields = [model_field.column for model_field in self.model._meta.fields]
            self.add_fields(fields)
825566
def contribute_to_class(self, model, name, **kwargs):
        
        super(LocalizedField, self).contribute_to_class(model, name, **kwargs)
        setattr(model, self.name, self.descriptor_class(self))
251812
def configure_field(self, field):
        """"""
        from .models import Indexable

        # This is for reverse relations, which do not have a db column
        if field.auto_created and field.is_relation:
            if isinstance(field, (ForeignObjectRel, ManyToOneRel)) and issubclass(field.related_model, Indexable):
                related_properties = field.related_model.search_objects.mapping.properties.properties.to_dict()
                self.field(field.name, {"type": "nested", "properties": related_properties})
                return

        if field.get_internal_type() == "ManyToManyField" and issubclass(field.rel.to, Indexable):

            related_properties = field.rel.to.search_objects.mapping.properties.properties.to_dict()
            self.field(field.name, {"type": "nested", "properties": related_properties})
            return

        if isinstance(field, models.ForeignKey):
            # This is a related field, so it should maybe be nested?

            # We only want to nest fields when they are indexable, and not parent pointers.
            if issubclass(field.rel.to, Indexable) and not field.rel.parent_link:

                related_properties = field.rel.to.search_objects.mapping.properties.properties.to_dict()
                self.field(field.name, {"type": "nested", "properties": related_properties})
                return

        db_column, attname = field.db_column, field.attname

        field_args = FIELD_MAPPINGS.get(field.get_internal_type())
        if field_args:
            self.field(db_column or attname, field_args)
        else:
            raise Warning("Can't find {}".format(field.get_internal_type()))
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
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
168979
def import_field(self, field, obj, data, is_m2m=False):
        
        if field.attribute and field.column_name in data:
            field.save(obj, data, is_m2m)
359702
def add_field(self, name, ftype, docfield=None):
        
        self.schema.add_field(name, ftype)
        self[name] = docfield or DocField.FromType(ftype)
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)
111031
def create_model(cls, name, field=None):
        
        if field:
            attrs = {'name': name, 'field': field}
        else:
            attrs = {'name': name, 'field': {'_id': ObjectId()}}

        return type(str(name), (cls, ), attrs)()
368103
def get_field(self, field_name):
        """"""
        for attr_name, field in self:
            if field_name == attr_name:
                return field

        raise errors.FieldNotFound('Field not found', field_name)
508894
def add_field(self, name, label, field_type, *args, **kwargs):
        
        if name in self._dyn_fields:
            raise AttributeError('Field already added to the form.')
        else:
            self._dyn_fields[name] = {'label': label, 'type': field_type,
                                      'args': args, 'kwargs': kwargs}
138629
function model (doc, fields) {
    if (!(this instanceof model))
      return new model(doc, fields);
    Model.call(this, doc, fields);
  }