本文整理汇总了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),
]
示例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.'
)
示例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
示例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.'
)
示例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
示例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
示例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
示例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)
示例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
示例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')
)
示例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
示例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
示例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
示例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
示例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