当前位置: 首页>>代码示例>>Python>>正文


Python fields.DateField方法代码示例

本文整理汇总了Python中django.db.models.fields.DateField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.DateField方法的具体用法?Python fields.DateField怎么用?Python fields.DateField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.fields的用法示例。


在下文中一共展示了fields.DateField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_django_field_map

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_django_field_map(self):
        from django.db.models import fields as djf
        return [
            (djf.AutoField, PrimaryKeyField),
            (djf.BigIntegerField, BigIntegerField),
            # (djf.BinaryField, BlobField),
            (djf.BooleanField, BooleanField),
            (djf.CharField, CharField),
            (djf.DateTimeField, DateTimeField),  # Extends DateField.
            (djf.DateField, DateField),
            (djf.DecimalField, DecimalField),
            (djf.FilePathField, CharField),
            (djf.FloatField, FloatField),
            (djf.IntegerField, IntegerField),
            (djf.NullBooleanField, partial(BooleanField, null=True)),
            (djf.TextField, TextField),
            (djf.TimeField, TimeField),
            (djf.related.ForeignKey, ForeignKeyField),
        ] 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:21,代码来源:djpeewee.py

示例2: check_expression_support

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:operations.py

示例3: get_db_converters

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_db_converters(self, expression):
        converters = super().get_db_converters(expression)
        internal_type = expression.output_field.get_internal_type()
        if internal_type == 'DateTimeField':
            converters.append(self.convert_datetimefield_value)
        elif internal_type == 'DateField':
            converters.append(self.convert_datefield_value)
        elif internal_type == 'TimeField':
            converters.append(self.convert_timefield_value)
        # Converter for Col is added with Database.register_converter()
        # in base.py.
        elif internal_type == 'DecimalField' and not isinstance(expression, Col):
            converters.append(self.convert_decimalfield_value)
        elif internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        elif internal_type in ('NullBooleanField', 'BooleanField'):
            converters.append(self.convert_booleanfield_value)
        return converters 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:operations.py

示例4: check_expression_support

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:20,代码来源:operations.py

示例5: get_db_converters

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_db_converters(self, expression):
        converters = super().get_db_converters(expression)
        internal_type = expression.output_field.get_internal_type()
        if internal_type == 'DateTimeField':
            converters.append(self.convert_datetimefield_value)
        elif internal_type == 'DateField':
            converters.append(self.convert_datefield_value)
        elif internal_type == 'TimeField':
            converters.append(self.convert_timefield_value)
        elif internal_type == 'DecimalField':
            converters.append(self.get_decimalfield_converter(expression))
        elif internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        elif internal_type in ('NullBooleanField', 'BooleanField'):
            converters.append(self.convert_booleanfield_value)
        return converters 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:18,代码来源:operations.py

示例6: check_expression_support

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                    if isinstance(output_field, bad_fields):
                        raise NotImplementedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        )
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass 
开发者ID:Yeah-Kun,项目名称:python,代码行数:19,代码来源:operations.py

示例7: get_db_converters

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_db_converters(self, expression):
        converters = super(DatabaseOperations, self).get_db_converters(expression)
        internal_type = expression.output_field.get_internal_type()
        if internal_type == 'DateTimeField':
            converters.append(self.convert_datetimefield_value)
        elif internal_type == 'DateField':
            converters.append(self.convert_datefield_value)
        elif internal_type == 'TimeField':
            converters.append(self.convert_timefield_value)
        elif internal_type == 'DecimalField':
            converters.append(self.convert_decimalfield_value)
        elif internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        elif internal_type in ('NullBooleanField', 'BooleanField'):
            converters.append(self.convert_booleanfield_value)
        return converters 
开发者ID:Yeah-Kun,项目名称:python,代码行数:18,代码来源:operations.py

示例8: build_schema_from_model

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def build_schema_from_model(model):
    field_mappings = {
        model_fields.BigIntegerField: "INTEGER",
        model_fields.CharField: "STRING",
        model_fields.DateField: "DATE",
        model_fields.FloatField: "FLOAT",
        model_fields.DecimalField: "NUMERIC",
        model_fields.IntegerField: "INTEGER",
        model_fields.BooleanField: "BOOLEAN",
        model_fields.NullBooleanField: "BOOLEAN",
        model_fields.TextField: "STRING",
        related_fields.ForeignKey: "INTEGER",
        related_fields.OneToOneField: "INTEGER",
    }

    fields = [
        (f.name, field_mappings[type(f)])
        for f in model._meta.fields
        if not f.auto_created
    ]

    return build_schema(*fields) 
开发者ID:ebmdatalab,项目名称:openprescribing,代码行数:24,代码来源:bigquery.py

示例9: _build_search_filter

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def _build_search_filter(cls, field_name):
    if field_name == "bnf_code":
        return _build_search_filter_bnf_code_prefox()

    field = cls._meta.get_field(field_name)
    builder = {
        ForeignKey: _build_search_filter_fk,
        ManyToOneRel: _build_search_filter_rev_fk,
        OneToOneRel: _build_search_filter_rev_fk,
        fields.CharField: _build_search_filter_char,
        fields.DateField: _build_search_filter_date,
        fields.BooleanField: _build_search_filter_boolean,
        fields.DecimalField: _build_search_filter_decimal,
    }[type(field)]
    search_filter = builder(field)
    search_filter["id"] = field_name
    return search_filter 
开发者ID:ebmdatalab,项目名称:openprescribing,代码行数:19,代码来源:build_search_filters.py

示例10: get_feedback

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_feedback(self):
        """ Return all feedback for the participant.

        Activity chairs see the complete history of feedback (without the normal
        "clean slate" period). The only exception is that activity chairs cannot
        see their own feedback.
        """
        return (
            models.Feedback.everything.filter(participant=self.object.participant)
            .exclude(participant=self.chair)
            .select_related('leader', 'trip')
            .prefetch_related('leader__leaderrating_set')
            .annotate(
                display_date=Least('trip__trip_date', Cast('time_created', DateField()))
            )
            .order_by('-display_date')
        ) 
开发者ID:DavidCain,项目名称:mitoc-trips,代码行数:19,代码来源:applications.py

示例11: check_expression_support

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            try:
                output_field = expression.input_field.output_field
                if isinstance(output_field, bad_fields):
                    raise NotImplementedError(
                        'You cannot use Sum, Avg, StdDev and Variance aggregations '
                        'on date/time fields in sqlite3 '
                        'since date/time is saved as text.')
            except FieldError:
                # not every sub-expression has an output_field which is fine to
                # ignore
                pass 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:operations.py

示例12: get_db_converters

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def get_db_converters(self, expression):
        converters = super(DatabaseOperations, self).get_db_converters(expression)
        internal_type = expression.output_field.get_internal_type()
        if internal_type == 'DateTimeField':
            converters.append(self.convert_datetimefield_value)
        elif internal_type == 'DateField':
            converters.append(self.convert_datefield_value)
        elif internal_type == 'TimeField':
            converters.append(self.convert_timefield_value)
        elif internal_type == 'DecimalField':
            converters.append(self.convert_decimalfield_value)
        elif internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        return converters 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:16,代码来源:operations.py

示例13: __init__

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def __init__(self, lookup, lookup_type):
        super(Date, self).__init__(output_field=fields.DateField())
        self.lookup = lookup
        self.col = None
        self.lookup_type = lookup_type 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:expressions.py

示例14: resolve_expression

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
        copy = self.copy()
        copy.col = query.resolve_ref(self.lookup, allow_joins, reuse, summarize)
        field = copy.col.output_field
        assert isinstance(field, fields.DateField), "%r isn't a DateField." % field.name
        if settings.USE_TZ:
            assert not isinstance(field, fields.DateTimeField), (
                "%r is a DateTimeField, not a DateField." % field.name
            )
        return copy 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:expressions.py

示例15: sql_map_lambda

# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import DateField [as 别名]
def sql_map_lambda(self, query_set):
        field_to_table_lookup = map_to_dict(lambda tup: [tup[1], tup[0]], query_set.query.select)
        def sql_map(path):
            """
                Like field_map, but instead produces a sql version of the mapping.
                Since our export functionality sends sql to ogr, we need to handle
                all the formatting in the sql. We can do this by overriding the normal
                select value with a function (e.g. select updated_date becomes select format(update_data).
                In order to do this we create an extra clause for the Django QuerySet since it sadly
                doesn't have a built-in ability to decorate selections with functions
            :param path:
            :param field_class_path:
            :return: An array with two values, the path and the mapping. If no mapping
            is needed, an array with [path, path] is returned. This way the path is used as an extra
            value and the column order is preserved. Django nonsensically puts the extra fields before
            the normal fields, even if their names match. Apparently they didn't considered the situation
            of replacing a normal column select with a formatted column select, or they don't expect
            raw sql to be used.
            """

            full_column_name = '%s.%s' % (field_to_table_lookup.get(path), path.split('__')[-1]) if field_to_table_lookup.get(path) else path
            field_class_path = self.result_map.field_lookup.get(path)
            if not field_class_path:
                return None
            resolved_field_class = resolve_module_attr(field_class_path)
            if resolved_field_class and issubclass(resolved_field_class, DateField):
                # Format the date to match our prefered style (gotta love SQL :< )
                return [path,
                        "to_char({0}, 'YYYY-MM-DD') || 'T' || to_char({0}, 'HH:MI:SS') || to_char(extract(TIMEZONE_HOUR FROM {0}), 'fm00') || ':' || to_char(extract(TIMEZONE_MINUTE FROM {0}), 'fm00')".format(full_column_name)]
            return None
        return sql_map 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:33,代码来源:layer_selection.py


注:本文中的django.db.models.fields.DateField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。