本文整理汇总了Python中django.db.models.DateField方法的典型用法代码示例。如果您正苦于以下问题:Python models.DateField方法的具体用法?Python models.DateField怎么用?Python models.DateField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models
的用法示例。
在下文中一共展示了models.DateField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_queryset
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def get_queryset(self):
date = self._extract_date()
user = self.request.user
queryset = get_user_model().objects.values("id")
queryset = queryset.annotate(date=Value(date, DateField()))
# last_reported_date filter is set, a date can only be calucated
# for users with either at least one absence or report
if date is None:
users_with_reports = Report.objects.values("user").distinct()
users_with_absences = Absence.objects.values("user").distinct()
active_users = users_with_reports.union(users_with_absences)
queryset = queryset.filter(id__in=active_users)
queryset = queryset.annotate(
pk=Concat("id", Value("_"), "date", output_field=CharField())
)
if not user.is_superuser:
queryset = queryset.filter(Q(id=user.id) | Q(supervisors=user))
return queryset
示例2: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field.rel, models.ManyToManyRel):
return ', '.join([smart_text(obj) for obj in value.all()])
else:
return smart_text(value)
示例3: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例4: _check_date_hierarchy
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def _check_date_hierarchy(self, cls, model):
""" Check that date_hierarchy refers to DateField or DateTimeField. """
if cls.date_hierarchy is None:
return []
else:
try:
field = model._meta.get_field(cls.date_hierarchy)
except FieldDoesNotExist:
return refer_to_missing_field(option='date_hierarchy',
field=cls.date_hierarchy,
model=model, obj=cls, id='admin.E127')
else:
if not isinstance(field, (models.DateField, models.DateTimeField)):
return must_be('a DateField or DateTimeField', option='date_hierarchy',
obj=cls, id='admin.E128')
else:
return []
示例5: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例6: _check_date_hierarchy
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def _check_date_hierarchy(self, obj):
""" Check that date_hierarchy refers to DateField or DateTimeField. """
if obj.date_hierarchy is None:
return []
else:
try:
field = get_fields_from_path(obj.model, obj.date_hierarchy)[-1]
except (NotRelationField, FieldDoesNotExist):
return [
checks.Error(
"The value of 'date_hierarchy' refers to '%s', which "
"does not refer to a Field." % obj.date_hierarchy,
obj=obj.__class__,
id='admin.E127',
)
]
else:
if not isinstance(field, (models.DateField, models.DateTimeField)):
return must_be('a DateField or DateTimeField', option='date_hierarchy', obj=obj, id='admin.E128')
else:
return []
示例7: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field.remote_field, models.ManyToManyRel):
return ', '.join([smart_text(obj) for obj in value.all()])
else:
return smart_text(value)
示例8: build_default_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def build_default_field(self, field, model):
choices = getattr(field, "choices", None)
if choices:
return forms.ChoiceField(
required=False,
label=_("Default value"),
choices=[(None, "-----------")] + list(choices),
)
if not (model is Member and field.name == "number"):
if isinstance(field, models.CharField):
return forms.CharField(required=False, label=_("Default value"))
elif isinstance(field, models.DecimalField):
return forms.DecimalField(
required=False,
label=_("Default value"),
max_digits=field.max_digits,
decimal_places=field.decimal_places,
)
elif isinstance(field, models.DateField):
return forms.CharField(required=False, label=_("Other/fixed date"))
示例9: load_dates
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def load_dates(context):
data = {}
cl = context.get('cl')
if cl.has_filters:
for spec in cl.filter_specs:
# 自定义的filter,没有field
if not hasattr(spec, 'field'):
continue
field = spec.field
field_type = None
if isinstance(field, models.DateTimeField):
field_type = 'datetime'
elif isinstance(field, models.DateField):
field_type = 'date'
elif isinstance(field, models.TimeField):
field_type = 'time'
if field_type:
data[spec.field_path] = field_type
context['date_field'] = data
return '<script type="text/javascript">var searchDates={}</script>'.format(json.dumps(data, cls=LazyEncoder))
示例10: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# BooleanField needs special-case null-handling, so it comes before the
# general null test.
elif isinstance(field, models.BooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例11: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例12: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if field.flatchoices:
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例13: _check_date_hierarchy
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def _check_date_hierarchy(self, obj):
""" Check that date_hierarchy refers to DateField or DateTimeField. """
if obj.date_hierarchy is None:
return []
else:
try:
field = obj.model._meta.get_field(obj.date_hierarchy)
except FieldDoesNotExist:
return refer_to_missing_field(option='date_hierarchy',
field=obj.date_hierarchy,
model=obj.model, obj=obj, id='admin.E127')
else:
if not isinstance(field, (models.DateField, models.DateTimeField)):
return must_be('a DateField or DateTimeField', option='date_hierarchy',
obj=obj, id='admin.E128')
else:
return []
示例14: test
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def test(cls, field, request, params, model, admin_view, field_path):
return isinstance(field, models.DateField)
示例15: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DateField [as 别名]
def display_for_field(value, field, html=True, only_date=True):
if getattr(field, 'flatchoices', None):
if html and field.name == 'color' and value:
return make_color_icon(value)
return dict(field.flatchoices).get(value, '')
elif html and (isinstance(field, (models.BooleanField, models.NullBooleanField))):
return make_boolean_icon(value)
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
boolchoice = {False: "否", True: "是"}
return boolchoice.get(value)
elif value is None:
return ""
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.ForeignKey) and value:
rel_obj = field.related_model.objects.get(pk=value)
if html and COLOR_FK_FIELD and isinstance(rel_obj, Option):
text_color = rel_obj.color
if not text_color:
text_color = 'text-info'
safe_value = format_html(
'<span class="text-{}">{}</span>', text_color, rel_obj.text)
return safe_value
return force_text(rel_obj)
elif isinstance(field, models.TextField) and value:
return force_text(value)
elif isinstance(field, models.DateTimeField):
if only_date:
return formats.date_format(value)
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value)