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


Python models.DurationField方法代码示例

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


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

示例1: test_date_subtraction

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_date_subtraction(self):
        queryset = Experiment.objects.annotate(
            completion_duration=ExpressionWrapper(
                F('completed') - F('assigned'), output_field=models.DurationField()
            )
        )

        at_least_5_days = {e.name for e in queryset.filter(completion_duration__gte=datetime.timedelta(days=5))}
        self.assertEqual(at_least_5_days, {'e3', 'e4', 'e5'})

        at_least_120_days = {e.name for e in queryset.filter(completion_duration__gte=datetime.timedelta(days=120))}
        self.assertEqual(at_least_120_days, {'e5'})

        less_than_5_days = {e.name for e in queryset.filter(completion_duration__lt=datetime.timedelta(days=5))}
        expected = {'e0', 'e2'}
        if connection.features.supports_microsecond_precision:
            expected.add('e1')
        self.assertEqual(less_than_5_days, expected) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:20,代码来源:tests.py

示例2: test_durationfield_add

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_durationfield_add(self):
        zeros = [e.name for e in Experiment.objects.filter(start=F('start') + F('estimated_time'))]
        self.assertEqual(zeros, ['e0'])

        end_less = [e.name for e in Experiment.objects.filter(end__lt=F('start') + F('estimated_time'))]
        self.assertEqual(end_less, ['e2'])

        delta_math = [
            e.name for e in
            Experiment.objects.filter(end__gte=F('start') + F('estimated_time') + datetime.timedelta(hours=1))
        ]
        self.assertEqual(delta_math, ['e4'])

        queryset = Experiment.objects.annotate(shifted=ExpressionWrapper(
            F('start') + Value(None, output_field=models.DurationField()),
            output_field=models.DateTimeField(),
        ))
        self.assertIsNone(queryset.first().shifted) 
开发者ID:nesdis,项目名称:djongo,代码行数:20,代码来源:tests.py

示例3: test_time_subtraction

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_time_subtraction(self):
        Time.objects.create(time=datetime.time(12, 30, 15, 2345))
        queryset = Time.objects.annotate(
            difference=ExpressionWrapper(
                F('time') - Value(datetime.time(11, 15, 0), output_field=models.TimeField()),
                output_field=models.DurationField(),
            )
        )
        self.assertEqual(
            queryset.get().difference,
            datetime.timedelta(hours=1, minutes=15, seconds=15, microseconds=2345)
        )

        queryset = Time.objects.annotate(difference=ExpressionWrapper(
            F('time') - Value(None, output_field=models.TimeField()),
            output_field=models.DurationField(),
        ))
        self.assertIsNone(queryset.first().difference)

        queryset = Time.objects.annotate(shifted=ExpressionWrapper(
            F('time') - Value(None, output_field=models.DurationField()),
            output_field=models.TimeField(),
        ))
        self.assertIsNone(queryset.first().shifted) 
开发者ID:nesdis,项目名称:djongo,代码行数:26,代码来源:tests.py

示例4: __init__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def __init__(self, expression, *, output_field=None, **extra):
        super().__init__(expression, output_field=output_field or DurationField(), **extra) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:4,代码来源:functions.py

示例5: __init__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def __init__(self, expression, **extra):
        output_field = extra.pop('output_field', DurationField())
        super(SecondsToInterval, self).__init__(expression, output_field=output_field, **extra) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:5,代码来源:functions.py

示例6: test_should_auto_convert_duration

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_should_auto_convert_duration():
    assert_conversion(models.DurationField, graphene.Float) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:4,代码来源:test_converter.py

示例7: test_time_subtraction

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_time_subtraction(self):
        if connection.features.supports_microsecond_precision:
            time = datetime.time(12, 30, 15, 2345)
            timedelta = datetime.timedelta(hours=1, minutes=15, seconds=15, microseconds=2345)
        else:
            time = datetime.time(12, 30, 15)
            timedelta = datetime.timedelta(hours=1, minutes=15, seconds=15)
        Time.objects.create(time=time)
        queryset = Time.objects.annotate(
            difference=ExpressionWrapper(
                F('time') - Value(datetime.time(11, 15, 0), output_field=models.TimeField()),
                output_field=models.DurationField(),
            )
        )
        self.assertEqual(queryset.get().difference, timedelta) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:tests.py

示例8: test_date_minus_duration

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_date_minus_duration(self):
        self.skipTest("TODO fix TypeError: not enough arguments for format string")
        # QUERY = 'SELECT [expressions_experiment].[id], [expressions_experiment].[name], [expressions_experiment].[assigned], [expressions_experiment].[completed], [expressions_experiment].[estimated_time], [expressions_experiment].[start], [expressions_experiment].[end] FROM [expressions_experiment] WHERE [expressions_experiment].[assigned] < ((DATEADD(MICROSECOND, (-1 * (%s %% 1000000)), CAST(DATEADD(SECOND, (%s / 1000000), CAST([expressions_experiment].[completed] as datetime2)) as datetime2)))) ORDER BY [expressions_experiment].[name] ASC' - PARAMS = (345600000000,); args=(345600000000,)
        more_than_4_days = Experiment.objects.filter(
            assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=models.DurationField())
        )
        self.assertQuerysetEqual(more_than_4_days, ['e3', 'e4', 'e5'], lambda e: e.name) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:9,代码来源:tests.py

示例9: test_update_duration

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_update_duration(self):
        CaseTestModel.objects.update(
            duration=Case(
                # fails on sqlite if output_field is not set explicitly on all
                # Values containing timedeltas
                When(integer=1, then=Value(timedelta(1), output_field=models.DurationField())),
                When(integer=2, then=Value(timedelta(2), output_field=models.DurationField())),
            ),
        )
        self.assertQuerysetEqual(
            CaseTestModel.objects.all().order_by('pk'),
            [(1, timedelta(1)), (2, timedelta(2)), (3, None), (2, timedelta(2)), (3, None), (3, None), (4, None)],
            transform=attrgetter('integer', 'duration')
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:tests.py

示例10: test_date_subtraction

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_date_subtraction(self):
        queryset = Experiment.objects.annotate(
            completion_duration=ExpressionWrapper(
                F('completed') - F('assigned'), output_field=models.DurationField()
            )
        )

        at_least_5_days = {e.name for e in queryset.filter(completion_duration__gte=datetime.timedelta(days=5))}
        self.assertEqual(at_least_5_days, {'e3', 'e4', 'e5'})

        at_least_120_days = {e.name for e in queryset.filter(completion_duration__gte=datetime.timedelta(days=120))}
        self.assertEqual(at_least_120_days, {'e5'})

        less_than_5_days = {e.name for e in queryset.filter(completion_duration__lt=datetime.timedelta(days=5))}
        self.assertEqual(less_than_5_days, {'e0', 'e1', 'e2'}) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:tests.py

示例11: test_time_subtraction

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_time_subtraction(self):
        Time.objects.create(time=datetime.time(12, 30, 15, 2345))
        queryset = Time.objects.annotate(
            difference=ExpressionWrapper(
                F('time') - Value(datetime.time(11, 15, 0), output_field=models.TimeField()),
                output_field=models.DurationField(),
            )
        )
        self.assertEqual(
            queryset.get().difference,
            datetime.timedelta(hours=1, minutes=15, seconds=15, microseconds=2345)
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例12: test_datetime_subtraction_microseconds

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_datetime_subtraction_microseconds(self):
        delta = datetime.timedelta(microseconds=8999999999999999)
        Experiment.objects.update(end=F('start') + delta)
        qs = Experiment.objects.annotate(
            delta=ExpressionWrapper(F('end') - F('start'), output_field=models.DurationField())
        )
        for e in qs:
            self.assertEqual(e.delta, delta) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例13: test_date_minus_duration

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_date_minus_duration(self):
        more_than_4_days = Experiment.objects.filter(
            assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=models.DurationField())
        )
        self.assertQuerysetEqual(more_than_4_days, ['e3', 'e4', 'e5'], lambda e: e.name) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例14: test_subtract_temporals

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_subtract_temporals(self):
        duration_field = DurationField()
        duration_field_internal_type = duration_field.get_internal_type()
        msg = (
            'This backend does not support %s subtraction.' %
            duration_field_internal_type
        )
        with self.assertRaisesMessage(NotSupportedError, msg):
            self.ops.subtract_temporals(duration_field_internal_type, None, None) 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_operations.py

示例15: test_formfield

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import DurationField [as 别名]
def test_formfield(self):
        field = models.DurationField()
        self.assertIsInstance(field.formfield(), forms.DurationField) 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_durationfield.py


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