當前位置: 首頁>>代碼示例>>Python>>正文


Python expressions.F屬性代碼示例

本文整理匯總了Python中django.db.models.expressions.F屬性的典型用法代碼示例。如果您正苦於以下問題:Python expressions.F屬性的具體用法?Python expressions.F怎麽用?Python expressions.F使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.db.models.expressions的用法示例。


在下文中一共展示了expressions.F屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: datetimes

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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=DateTime(field_name, kind, 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:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:query.py

示例2: datetimes

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例3: overall_status

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def overall_status(self):
        # chord_unlock doesn't use the result backed, so best to ignore
        subtasks = self.family.exclude(type='celery.chord_unlock')
        subtasks = subtasks.annotate(_status=F('result__status'))
        # If we are to get distinct _status values, we must order_by('_status')
        subtasks = subtasks.order_by('_status')
        statuses = subtasks.values_list('_status', flat=True)
        statuses = statuses.distinct()
        num_statuses = len(statuses)
        if num_statuses > 1:
            if 'FAILURE' in statuses:
                return 'FAILURE'
            return 'STARTED'
        # It's possible for all statuses to equal None, in which case we
        # can call them 'PENDING'.
        return statuses[0] or 'PENDING' 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:18,代碼來源:models.py

示例4: get_context_data

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def get_context_data(self, **kwargs):
        context = super(CommentedDetailView, self).get_context_data(**kwargs)
        queryset = Comment.objects.filter(hidden=False, page=self.get_comment_page())
        context['has_comments'] = queryset.exists()
        context['comment_lock'] = self.is_comment_locked()
        queryset = queryset.select_related('author__user').defer('author__about').annotate(revisions=Count('versions'))

        if self.request.user.is_authenticated:
            queryset = queryset.annotate(vote_score=Coalesce(RawSQLColumn(CommentVote, 'score'), Value(0)))
            profile = self.request.profile
            unique_together_left_join(queryset, CommentVote, 'comment', 'voter', profile.id)
            context['is_new_user'] = (not self.request.user.is_staff and
                                      not profile.submission_set.filter(points=F('problem__points')).exists())
        context['comment_list'] = queryset
        context['vote_hide_threshold'] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD

        return context 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:19,代碼來源:comments.py

示例5: datetimes

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例6: datetimes

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例7: test_array_agg_charfield_ordering

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def test_array_agg_charfield_ordering(self):
        ordering_test_cases = (
            (F('char_field').desc(), ['Foo4', 'Foo3', 'Foo2', 'Foo1']),
            (F('char_field').asc(), ['Foo1', 'Foo2', 'Foo3', 'Foo4']),
            (F('char_field'), ['Foo1', 'Foo2', 'Foo3', 'Foo4']),
            ([F('boolean_field'), F('char_field').desc()], ['Foo4', 'Foo2', 'Foo3', 'Foo1']),
            ((F('boolean_field'), F('char_field').desc()), ['Foo4', 'Foo2', 'Foo3', 'Foo1']),
            ('char_field', ['Foo1', 'Foo2', 'Foo3', 'Foo4']),
            ('-char_field', ['Foo4', 'Foo3', 'Foo2', 'Foo1']),
        )
        for ordering, expected_output in ordering_test_cases:
            with self.subTest(ordering=ordering, expected_output=expected_output):
                values = AggregateTestModel.objects.aggregate(
                    arrayagg=ArrayAgg('char_field', ordering=ordering)
                )
                self.assertEqual(values, {'arrayagg': expected_output}) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_aggregates.py

示例8: dates

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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=Date(field_name, kind),
            plain_field=F(field_name)
        ).values_list(
            'datefield', flat=True
        ).distinct().filter(plain_field__isnull=False).order_by(('-' if order == 'DESC' else '') + 'datefield') 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:query.py

示例9: dates

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例10: clean

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def clean(self):
        if self.request is not None and self.request.user.is_authenticated:
            profile = self.request.profile
            if profile.mute:
                raise ValidationError(_('Your part is silent, little toad.'))
            elif (not self.request.user.is_staff and
                  not profile.submission_set.filter(points=F('problem__points')).exists()):
                raise ValidationError(_('You need to have solved at least one problem '
                                        'before your voice can be heard.'))
        return super(CommentForm, self).clean() 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:12,代碼來源:comments.py

示例11: dates

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例12: get_ordering_field_columns

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def get_ordering_field_columns(self):
        """
        Return an OrderedDict of ordering field column numbers and asc/desc.
        """
        # We must cope with more than one column having the same underlying sort
        # field, so we base things on column numbers.
        ordering = self._get_default_ordering()
        ordering_fields = OrderedDict()
        if ORDER_VAR not in self.params:
            # for ordering specified on ModelAdmin or model Meta, we don't know
            # the right column numbers absolutely, because there might be more
            # than one column associated with that ordering, so we guess.
            for field in ordering:
                if isinstance(field, (Combinable, OrderBy)):
                    if not isinstance(field, OrderBy):
                        field = field.asc()
                    if isinstance(field.expression, F):
                        order_type = 'desc' if field.descending else 'asc'
                        field = field.expression.name
                    else:
                        continue
                elif field.startswith('-'):
                    field = field[1:]
                    order_type = 'desc'
                else:
                    order_type = 'asc'
                for index, attr in enumerate(self.list_display):
                    if self.get_ordering_field(attr) == field:
                        ordering_fields[index] = order_type
                        break
        else:
            for p in self.params[ORDER_VAR].split('.'):
                none, pfx, idx = p.rpartition('-')
                try:
                    idx = int(idx)
                except ValueError:
                    continue  # skip it
                ordering_fields[idx] = 'desc' if pfx == '-' else 'asc'
        return ordering_fields 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:41,代碼來源:main.py

示例13: _check_ordering_item

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def _check_ordering_item(self, obj, model, field_name, label):
        """ Check that `ordering` refers to existing fields. """
        if isinstance(field_name, (Combinable, OrderBy)):
            if not isinstance(field_name, OrderBy):
                field_name = field_name.asc()
            if isinstance(field_name.expression, F):
                field_name = field_name.expression.name
            else:
                return []
        if field_name == '?' and len(obj.ordering) != 1:
            return [
                checks.Error(
                    "The value of 'ordering' has the random ordering marker '?', "
                    "but contains other fields as well.",
                    hint='Either remove the "?", or remove the other fields.',
                    obj=obj.__class__,
                    id='admin.E032',
                )
            ]
        elif field_name == '?':
            return []
        elif LOOKUP_SEP in field_name:
            # Skip ordering in the format field1__field2 (FIXME: checking
            # this format would be nice, but it's a little fiddly).
            return []
        else:
            if field_name.startswith('-'):
                field_name = field_name[1:]
            if field_name == 'pk':
                return []
            try:
                model._meta.get_field(field_name)
            except FieldDoesNotExist:
                return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E033')
            else:
                return [] 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:38,代碼來源:checks.py

示例14: dates

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [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

示例15: render_last_exec

# 需要導入模塊: from django.db.models import expressions [as 別名]
# 或者: from django.db.models.expressions import F [as 別名]
def render_last_exec(self, record) -> Union[str, datetime.datetime]:
        """Render the last executed time.

        :param record: Record being processed in the table.
        :return: Datetime/string
        """
        log_item = self.workflow.logs.filter(
            user=self.user,
            name=models.Log.PLUGIN_EXECUTE,
            payload__name=record.name,
        ).order_by(F('created').desc()).first()
        if not log_item:
            return '--'
        return log_item.created 
開發者ID:abelardopardo,項目名稱:ontask_b,代碼行數:16,代碼來源:plugin_run.py


注:本文中的django.db.models.expressions.F屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。