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


Python functions.Trunc方法代码示例

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


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

示例1: datetimes

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def datetimes(self, field_name, kind, order='ASC', tzinfo=None):
        """
        Return a list of datetime objects representing all available
        datetimes for the given field_name, scoped to 'kind'.
        """
        assert kind in ("year", "month", "day", "hour", "minute", "second"), \
            "'kind' must be one of 'year', 'month', 'day', 'hour', 'minute' or 'second'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        if settings.USE_TZ:
            if tzinfo is None:
                tzinfo = timezone.get_current_timezone()
        else:
            tzinfo = None
        return self.annotate(
            datetimefield=Trunc(field_name, kind, output_field=DateTimeField(), tzinfo=tzinfo),
            plain_field=F(field_name)
        ).values_list(
            'datetimefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datetimefield') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:22,代码来源:query.py

示例2: datetimes

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def datetimes(self, field_name, kind, order='ASC', tzinfo=None):
        """
        Return a list of datetime objects representing all available
        datetimes for the given field_name, scoped to 'kind'.
        """
        assert kind in ('year', 'month', 'week', 'day', 'hour', 'minute', 'second'), \
            "'kind' must be one of 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        if settings.USE_TZ:
            if tzinfo is None:
                tzinfo = timezone.get_current_timezone()
        else:
            tzinfo = None
        return self.annotate(
            datetimefield=Trunc(field_name, kind, output_field=DateTimeField(), tzinfo=tzinfo),
            plain_field=F(field_name)
        ).values_list(
            'datetimefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datetimefield') 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:22,代码来源:query.py

示例3: datetimes

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def datetimes(self, field_name, kind, order='ASC', tzinfo=None):
        """
        Returns a list of datetime objects representing all available
        datetimes for the given field_name, scoped to 'kind'.
        """
        assert kind in ("year", "month", "day", "hour", "minute", "second"), \
            "'kind' must be one of 'year', 'month', 'day', 'hour', 'minute' or 'second'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        if settings.USE_TZ:
            if tzinfo is None:
                tzinfo = timezone.get_current_timezone()
        else:
            tzinfo = None
        return self.annotate(
            datetimefield=Trunc(field_name, kind, output_field=DateTimeField(), tzinfo=tzinfo),
            plain_field=F(field_name)
        ).values_list(
            'datetimefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datetimefield') 
开发者ID:Yeah-Kun,项目名称:python,代码行数:22,代码来源:query.py

示例4: dates

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def dates(self, field_name, kind, order='ASC'):
        """
        Return a list of date objects representing all available dates for
        the given field_name, scoped to 'kind'.
        """
        assert kind in ("year", "month", "day"), \
            "'kind' must be one of 'year', 'month' or 'day'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        return self.annotate(
            datefield=Trunc(field_name, kind, output_field=DateField()),
            plain_field=F(field_name)
        ).values_list(
            'datefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datefield') 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:query.py

示例5: _truncate_delete_field

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def _truncate_delete_field(self):
        return Trunc('deleted_on', kind='minute') 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:4,代码来源:profiles.py

示例6: dates

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def dates(self, field_name, kind, order='ASC'):
        """
        Return a list of date objects representing all available dates for
        the given field_name, scoped to 'kind'.
        """
        assert kind in ('year', 'month', 'week', 'day'), \
            "'kind' must be one of 'year', 'month', 'week', or 'day'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        return self.annotate(
            datefield=Trunc(field_name, kind, output_field=DateField()),
            plain_field=F(field_name)
        ).values_list(
            'datefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datefield') 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:17,代码来源:query.py

示例7: dates

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def dates(self, field_name, kind, order='ASC'):
        """
        Returns a list of date objects representing all available dates for
        the given field_name, scoped to 'kind'.
        """
        assert kind in ("year", "month", "day"), \
            "'kind' must be one of 'year', 'month' or 'day'."
        assert order in ('ASC', 'DESC'), \
            "'order' must be either 'ASC' or 'DESC'."
        return self.annotate(
            datefield=Trunc(field_name, kind, output_field=DateField()),
            plain_field=F(field_name)
        ).values_list(
            'datefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datefield') 
开发者ID:Yeah-Kun,项目名称:python,代码行数:17,代码来源:query.py

示例8: get_status

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Trunc [as 别名]
def get_status(self, started=None, ended=None, use_ingest_time=False):
        """Returns ingest status information within the given time range grouped by strike process.

        :param started: Query ingests updated after this amount of time.
        :type started: :class:`datetime.datetime`
        :param ended: Query ingests updated before this amount of time.
        :type ended: :class:`datetime.datetime`
        :param use_ingest_time: Whether or not to group the status values by ingest time (False) or data time (True).
        :type use_ingest_time: bool
        :returns: The list of ingest status models that match the time range.
        :rtype: [:class:`ingest.models.IngestStatus`]
        """

        # Fetch a list of ingests
        ingests = Ingest.objects.filter(status='INGESTED')
        ingests = ingests.select_related('strike')
        ingests = ingests.defer('strike__configuration')

        # Apply time range filtering
        if started:
            if use_ingest_time:
                ingests = ingests.filter(ingest_ended__gte=started)
            else:
                ingests = ingests.filter(data_ended__gte=started)
        if ended:
            if use_ingest_time:
                ingests = ingests.filter(ingest_ended__lte=ended)
            else:
                ingests = ingests.filter(data_started__lte=ended)

        # Apply sorting and exclude any null values
        if use_ingest_time:
            ingests = ingests.exclude(ingest_ended__isnull=True).annotate(
                time=Trunc('ingest_ended', 'hour',
                           output_field=models.DateTimeField(blank=True, null=True))).order_by('time').values('time')
        else:
            ingests = ingests.exclude(data_started__isnull=True).annotate(
                time=Trunc('data_started', 'hour',
                           output_field=models.DateTimeField(blank=True, null=True))).order_by('time').values('time')

        ingests = ingests.annotate(files=Count('id'), size=Sum('file_size'))

        # Build a mapping of all possible strike processes
        fill_status = []
        for strike in Strike.objects.all().select_related('job', 'job__job_type'):
            strike_ingests = ingests.filter(strike__id=strike.id)

            if use_ingest_time:
                info = strike_ingests.aggregate(all_files=Sum('files'), all_sizes=Sum('file_size'),
                                                most_recent=Max('ingest_ended'))
            else:
                info = strike_ingests.aggregate(all_files=Sum('files'), all_sizes=Sum('file_size'),
                                                most_recent=Max('data_started'))
            ingest_status = IngestStatus(strike=strike, most_recent=info['most_recent'], files=info['all_files'],
                                         size=info['all_sizes'])
            time_slots = {item['time']: IngestCounts(item['time'], item['files'], item['size'])
                          for item in strike_ingests.values('time', 'size', 'files')}
            fill_status.append(self._fill_status(ingest_status, time_slots, started, ended))

        return fill_status 
开发者ID:ngageoint,项目名称:scale,代码行数:62,代码来源:models.py


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