當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.Field方法代碼示例

本文整理匯總了Python中django.db.models.fields.Field方法的典型用法代碼示例。如果您正苦於以下問題:Python fields.Field方法的具體用法?Python fields.Field怎麽用?Python fields.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.models.fields的用法示例。


在下文中一共展示了fields.Field方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:25,代碼來源:where.py

示例2: _get_current_field_from_assignment

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def _get_current_field_from_assignment(ctx: FunctionContext, django_context: DjangoContext) -> Optional[Field]:
    outer_model_info = helpers.get_typechecker_api(ctx).scope.active_class()
    if (outer_model_info is None
            or not helpers.is_model_subclass_info(outer_model_info, django_context)):
        return None

    field_name = None
    for stmt in outer_model_info.defn.defs.body:
        if isinstance(stmt, AssignmentStmt):
            if stmt.rvalue == ctx.context:
                if not isinstance(stmt.lvalues[0], NameExpr):
                    return None
                field_name = stmt.lvalues[0].name
                break
    if field_name is None:
        return None

    model_cls = django_context.get_model_class_by_fullname(outer_model_info.fullname)
    if model_cls is None:
        return None

    current_field = model_cls._meta.get_field(field_name)
    return current_field 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:25,代碼來源:fields.py

示例3: get_field_lookup_exact_type

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def get_field_lookup_exact_type(self, api: TypeChecker, field: Union[Field, ForeignObjectRel]) -> MypyType:
        if isinstance(field, (RelatedField, ForeignObjectRel)):
            related_model_cls = field.related_model
            primary_key_field = self.get_primary_key_field(related_model_cls)
            primary_key_type = self.get_field_get_type(api, primary_key_field, method='init')

            rel_model_info = helpers.lookup_class_typeinfo(api, related_model_cls)
            if rel_model_info is None:
                return AnyType(TypeOfAny.explicit)

            model_and_primary_key_type = UnionType.make_union([Instance(rel_model_info, []), primary_key_type])
            return helpers.make_optional(model_and_primary_key_type)

        field_info = helpers.lookup_class_typeinfo(api, field.__class__)
        if field_info is None:
            return AnyType(TypeOfAny.explicit)
        return helpers.get_private_descriptor_type(field_info, '_pyi_lookup_exact_type',
                                                   is_nullable=field.null) 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:20,代碼來源:context.py

示例4: get_field_set_type

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def get_field_set_type(self, api: TypeChecker, field: Union[Field, ForeignObjectRel], *, method: str) -> MypyType:
        """ Get a type of __set__ for this specific Django field. """
        target_field = field
        if isinstance(field, ForeignKey):
            target_field = field.target_field

        field_info = helpers.lookup_class_typeinfo(api, target_field.__class__)
        if field_info is None:
            return AnyType(TypeOfAny.from_error)

        field_set_type = helpers.get_private_descriptor_type(field_info, '_pyi_private_set_type',
                                                             is_nullable=self.get_field_nullability(field, method))
        if isinstance(target_field, ArrayField):
            argument_field_type = self.get_field_set_type(api, target_field.base_field, method=method)
            field_set_type = helpers.convert_any_to_type(field_set_type, argument_field_type)
        return field_set_type 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:18,代碼來源:context.py

示例5: get_field_get_type

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def get_field_get_type(self, api: TypeChecker, field: Union[Field, ForeignObjectRel], *, method: str) -> MypyType:
        """ Get a type of __get__ for this specific Django field. """
        field_info = helpers.lookup_class_typeinfo(api, field.__class__)
        if field_info is None:
            return AnyType(TypeOfAny.unannotated)

        is_nullable = self.get_field_nullability(field, method)
        if isinstance(field, RelatedField):
            related_model_cls = self.get_field_related_model_cls(field)
            if related_model_cls is None:
                return AnyType(TypeOfAny.from_error)

            if method == 'values':
                primary_key_field = self.get_primary_key_field(related_model_cls)
                return self.get_field_get_type(api, primary_key_field, method=method)

            model_info = helpers.lookup_class_typeinfo(api, related_model_cls)
            if model_info is None:
                return AnyType(TypeOfAny.unannotated)

            return Instance(model_info, [])
        else:
            return helpers.get_private_descriptor_type(field_info, '_pyi_private_get_type',
                                                       is_nullable=is_nullable) 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:26,代碼來源:context.py

示例6: _resolve_field_from_parts

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def _resolve_field_from_parts(self,
                                  field_parts: Iterable[str],
                                  model_cls: Type[Model]
                                  ) -> Union[Field, ForeignObjectRel]:
        currently_observed_model = model_cls
        field = None
        for field_part in field_parts:
            if field_part == 'pk':
                field = self.get_primary_key_field(currently_observed_model)
                continue

            field = currently_observed_model._meta.get_field(field_part)
            if isinstance(field, RelatedField):
                currently_observed_model = field.related_model
                model_name = currently_observed_model._meta.model_name
                if (model_name is not None
                        and field_part == (model_name + '_id')):
                    field = self.get_primary_key_field(currently_observed_model)

            if isinstance(field, ForeignObjectRel):
                currently_observed_model = field.related_model

        assert field is not None
        return field 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:26,代碼來源:context.py

示例7: get_private_descriptor_type

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def get_private_descriptor_type(type_info: TypeInfo, private_field_name: str, is_nullable: bool) -> MypyType:
    """ Return declared type of type_info's private_field_name (used for private Field attributes)"""
    sym = type_info.get(private_field_name)
    if sym is None:
        return AnyType(TypeOfAny.explicit)

    node = sym.node
    if isinstance(node, Var):
        descriptor_type = node.type
        if descriptor_type is None:
            return AnyType(TypeOfAny.explicit)

        if is_nullable:
            descriptor_type = make_optional(descriptor_type)
        return descriptor_type
    return AnyType(TypeOfAny.explicit) 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:18,代碼來源:helpers.py

示例8: _prepare

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def _prepare(self):
        """
        Hook used by Field.get_prep_lookup() to do custom preparation.
        """
        return self 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:expressions.py

示例9: __init__

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:expressions.py

示例10: get_srid

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
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 ### 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:fields.py

示例11: num_geom

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:query.py

示例12: __init__

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def __init__(self, sql, params, output_field=None):
        if output_field is None:
            output_field = fields.Field()
        self.sql, self.params = sql, params
        super().__init__(output_field=output_field) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:7,代碼來源:expressions.py

示例13: _details

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def _details(self, current_model, relation):
        direct = isinstance(relation, Field) or isinstance(relation, GenericForeignKey)
        model = relation.model._meta.concrete_model
        if model == current_model:
            model = None

        field = relation if direct else relation.field
        return relation, model, direct, bool(field.many_to_many)  # many_to_many can be None 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:10,代碼來源:tests.py

示例14: test_local_fields

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
def test_local_fields(self):
        def is_data_field(f):
            return isinstance(f, Field) and not f.many_to_many

        for model, expected_result in TEST_RESULTS['local_fields'].items():
            fields = model._meta.local_fields
            self.assertEqual([f.attname for f in fields], expected_result)
            for f in fields:
                self.assertEqual(f.model, model)
                self.assertTrue(is_data_field(f)) 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:12,代碼來源:tests.py

示例15: _get_model_fields

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import Field [as 別名]
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... 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:38,代碼來源:serializers.py


注:本文中的django.db.models.fields.Field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。