Python django.db.models.fields 模块,Field() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.db.models.fields.Field()

项目:rfw_utils    作者:h3l    | 项目源码 | 文件源码
def generate_fields(model, add=None, remove=None):
    if add is None:
        add = []
    if remove is None:
        remove = []

    remove.append("id")
    result = []
    for field in model._meta.get_fields():
        if isinstance(field, Field):
            result.append(field.name)
    for item in add:
        result.append(item)
    for item in remove:
        try:
            result.remove(item)
        except ValueError:
            pass

    return tuple(result)
项目:authserver    作者:jdelic    | 项目源码 | 文件源码
def get_form(self, req: HttpRequest, obj: Domain=None, **kwargs: Any) -> type:
        if req.GET.get("_prefill_key", "0") == "1":
            def formfield_callback(field: _ModelField, request: HttpRequest=None, **kwargs: Any) -> Type[_FormField]:
                f = self.formfield_for_dbfield(field, request=request, **kwargs)  # type: _FormField
                # f can be None if the dbfield does not get a FormField (like hidden fields
                # or auto increment IDs). Only the dbfield has a .name attribute.
                if f and field.name == "dkimkey":
                    if obj:
                        obj.dkimkey = RSA.generate(2048).exportKey("PEM").decode("utf-8")
                    else:
                        f.initial = RSA.generate(2048).exportKey("PEM").decode("utf-8")
                return f

            kwargs["formfield_callback"] = functools.partial(formfield_callback, request=req)

        form_t = super().get_form(req, obj, **kwargs)
        return form_t
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def process(self, lookup_type, value, connection):
        """
        Returns a tuple of data suitable for inclusion in a WhereNode
        instance.
        """
        # Because of circular imports, we need to import this here.
        from django.db.models.base import ObjectDoesNotExist
        try:
            if self.field:
                params = self.field.get_db_prep_lookup(lookup_type, value,
                    connection=connection, prepared=True)
                db_type = self.field.db_type(connection=connection)
            else:
                # This branch is used at times when we add a comparison to NULL
                # (we don't really want to waste time looking up the associated
                # field object at the calling location).
                params = Field().get_db_prep_lookup(lookup_type, value,
                    connection=connection, prepared=True)
                db_type = None
        except ObjectDoesNotExist:
            raise EmptyShortCircuit

        return (self.alias, self.col, db_type), params
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def _prepare(self, field):
        """
        Hook used by Field.get_prep_lookup() to do custom preparation.
        """
        return self
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def __init__(self, sql, params, output_field=None):
        if output_field is None:
            output_field = fields.Field()
        self.sql, self.params = sql, params
        super(RawSQL, self).__init__(output_field=output_field)
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:django    作者:alexsukhrin    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:django    作者:alexsukhrin    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:django-composite-foreignkey    作者:onysos    | 项目源码 | 文件源码
def get_lookup(self, main_field, for_remote, alias):
        """
        create a fake field for the lookup capability
        :param CompositeForeignKey main_field: the local fk
        :param Field for_remote: the remote field to match
        :return:
        """
项目:django-composite-foreignkey    作者:onysos    | 项目源码 | 文件源码
def get_lookup(self, main_field, for_remote, alias):
        """
        create a fake field for the lookup capability
        :param CompositeForeignKey main_field: the local fk
        :param Field for_remote: the remote field to match
        :return:
        """
        lookup_class = for_remote.get_lookup("exact")
        return lookup_class(for_remote.get_col(alias), self.value)
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def _get_model_fields(self, field_names, declared_fields, extra_kwargs):
        """
        Returns all the model fields that are being mapped to by fields
        on the serializer class.
        Returned as a dict of 'model field name' -> 'model field'.
        Used internally by `get_uniqueness_field_options`.
        """
        model = getattr(self.Meta, 'model')
        model_fields = {}

        for field_name in field_names:
            if field_name in declared_fields:
                # If the field is declared on the serializer
                field = declared_fields[field_name]
                source = field.source or field_name
            else:
                try:
                    source = extra_kwargs[field_name]['source']
                except KeyError:
                    source = field_name

            if '.' in source or source == '*':
                # Model fields will always have a simple source mapping,
                # they can't be nested attribute lookups.
                continue

            try:
                field = model._meta.get_field(source)
                if isinstance(field, DjangoModelField):
                    model_fields[source] = field
            except FieldDoesNotExist:
                pass

        return model_fields

    # Determine the validators to apply...
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:jianshu-api    作者:strugglingyouth    | 项目源码 | 文件源码
def _get_model_fields(self, field_names, declared_fields, extra_kwargs):
        """
        Returns all the model fields that are being mapped to by fields
        on the serializer class.
        Returned as a dict of 'model field name' -> 'model field'.
        Used internally by `get_uniqueness_field_options`.
        """
        model = getattr(self.Meta, 'model')
        model_fields = {}

        for field_name in field_names:
            if field_name in declared_fields:
                # If the field is declared on the serializer
                field = declared_fields[field_name]
                source = field.source or field_name
            else:
                try:
                    source = extra_kwargs[field_name]['source']
                except KeyError:
                    source = field_name

            if '.' in source or source == '*':
                # Model fields will always have a simple source mapping,
                # they can't be nested attribute lookups.
                continue

            try:
                field = model._meta.get_field(source)
                if isinstance(field, DjangoModelField):
                    model_fields[source] = field
            except FieldDoesNotExist:
                pass

        return model_fields

    # Determine the validators to apply...
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def __init__(self, sql, params, output_field=None):
        if output_field is None:
            output_field = fields.Field()
        self.sql, self.params = sql, params
        super(RawSQL, self).__init__(output_field=output_field)
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def __init__(self, sql, params, output_field=None):
        if output_field is None:
            output_field = fields.Field()
        self.sql, self.params = sql, params
        super(RawSQL, self).__init__(output_field=output_field)
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def get_srid(self, geom):
        """
        Returns the default SRID for the given geometry, taking into account
        the SRID set for the field.  For example, if the input geometry
        has no SRID, then that of the field will be returned.
        """
        gsrid = geom.srid  # SRID of given geometry.
        if gsrid is None or self.srid == -1 or (gsrid == -1 and self.srid != -1):
            return self.srid
        else:
            return gsrid

    # ### Routines overloaded from Field ###
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def num_geom(self, **kwargs):
        """
        Returns the number of geometries if the field is a
        GeometryCollection or Multi* Field in a `num_geom`
        attribute on each element of this GeoQuerySet; otherwise
        the sets with None.
        """
        return self._spatial_attribute('num_geom', {}, **kwargs)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def _prepare(self, field):
        """
        Hook used by Field.get_prep_lookup() to do custom preparation.
        """
        return self
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def __init__(self, sql, params, output_field=None):
        if output_field is None:
            output_field = fields.Field()
        self.sql, self.params = sql, params
        super(RawSQL, self).__init__(output_field=output_field)
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
def from_db_value(self, value, expression, connection, context):
        if value:
            if not isinstance(value, Geometry):
                value = Geometry(value)
            srid = value.srid
            if not srid and self.srid != -1:
                value.srid = self.srid
        return value

    # ### Routines overloaded from Field ###