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


Python constants.LOOKUP_SEP属性代码示例

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


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

示例1: get_distinct

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def get_distinct(self):
        """
        Returns a quoted list of fields to use in DISTINCT ON part of the query.

        Note that this method can alter the tables in the query, and thus it
        must be called before get_from_clause().
        """
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name
        result = []
        opts = self.query.get_meta()

        for name in self.query.distinct_fields:
            parts = name.split(LOOKUP_SEP)
            _, targets, alias, joins, path, _ = self._setup_joins(parts, opts, None)
            targets, alias, _ = self.query.trim_joins(targets, joins, path)
            for target in targets:
                result.append("%s.%s" % (qn(alias), qn2(target.column)))
        return result 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:compiler.py

示例2: _check_model_name_db_lookup_clashes

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _check_model_name_db_lookup_clashes(cls):
        errors = []
        model_name = cls.__name__
        if model_name.startswith('_') or model_name.endswith('_'):
            errors.append(
                checks.Error(
                    "The model name '%s' cannot start or end with an underscore "
                    "as it collides with the query lookup syntax." % model_name,
                    obj=cls,
                    id='models.E023'
                )
            )
        elif LOOKUP_SEP in model_name:
            errors.append(
                checks.Error(
                    "The model name '%s' cannot contain double underscores as "
                    "it collides with the query lookup syntax." % model_name,
                    obj=cls,
                    id='models.E024'
                )
            )
        return errors 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:24,代码来源:base.py

示例3: get_search_field

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def get_search_field(self, field_lookup, fields=None):
        if fields is None:
            fields = self.search_fields

        if LOOKUP_SEP in field_lookup:
            field_lookup, sub_field_name = field_lookup.split(LOOKUP_SEP, 1)
        else:
            sub_field_name = None

        for field in fields:
            if isinstance(field, self.TARGET_SEARCH_FIELD_TYPE) and field.field_name == field_lookup:
                return field

            # Note: Searching on a specific related field using
            # `.search(fields=…)` is not yet supported by Wagtail.
            # This method anticipates by already implementing it.
            if isinstance(field, RelatedFields) and field.field_name == field_lookup:
                return self.get_search_field(sub_field_name, field.fields) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:backend.py

示例4: get_distinct

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def get_distinct(self):
        """
        Returns a quoted list of fields to use in DISTINCT ON part of the query.

        Note that this method can alter the tables in the query, and thus it
        must be called before get_from_clause().
        """
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name
        result = []
        opts = self.query.get_meta()

        for name in self.query.distinct_fields:
            parts = name.split(LOOKUP_SEP)
            _, targets, alias, joins, path, _ = self._setup_joins(parts, opts, None)
            targets, alias, _ = self.query.trim_joins(targets, joins, path)
            for target in targets:
                if name in self.query.annotation_select:
                    result.append(name)
                else:
                    result.append("%s.%s" % (qn(alias), qn2(target.column)))
        return result 
开发者ID:Yeah-Kun,项目名称:python,代码行数:24,代码来源:compiler.py

示例5: get_distinct

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def get_distinct(self):
        """
        Returns a quoted list of fields to use in DISTINCT ON part of the query.

        Note that this method can alter the tables in the query, and thus it
        must be called before get_from_clause().
        """
        qn = self.quote_name_unless_alias
        qn2 = self.connection.ops.quote_name
        result = []
        opts = self.query.model._meta

        for name in self.query.distinct_fields:
            parts = name.split(LOOKUP_SEP)
            field, col, alias, _, _ = self._setup_joins(parts, opts, None)
            col, alias = self._final_join_removal(col, alias)
            result.append("%s.%s" % (qn(alias), qn2(col)))
        return result 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:compiler.py

示例6: _field_class_name

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _field_class_name(cls, field_class, lookup_expr):
        """
        Generate a suitable class name for the concrete field class. This is not
        completely reliable, as not all field class names are of the format
        <Type>Field.

        ex::

            BaseCSVFilter._field_class_name(DateTimeField, 'year__in')

            returns 'DateTimeYearInField'

        """
        # DateTimeField => DateTime
        type_name = field_class.__name__
        if type_name.endswith('Field'):
            type_name = type_name[:-5]

        # year__in => YearIn
        parts = lookup_expr.split(LOOKUP_SEP)
        expression_name = ''.join(p.capitalize() for p in parts)

        # DateTimeYearInField
        return str('%s%sField' % (type_name, expression_name)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:26,代码来源:filters.py

示例7: verbose_lookup_expr

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def verbose_lookup_expr(lookup_expr):
    """
    Get a verbose, more humanized expression for a given ``lookup_expr``.
    Each part in the expression is looked up in the ``FILTERS_VERBOSE_LOOKUPS``
    dictionary. Missing keys will simply default to itself.

    ex::

        >>> verbose_lookup_expr('year__lt')
        'year is less than'

        # with `FILTERS_VERBOSE_LOOKUPS = {}`
        >>> verbose_lookup_expr('year__lt')
        'year lt'

    """
    from .conf import settings as app_settings

    VERBOSE_LOOKUPS = app_settings.VERBOSE_LOOKUPS or {}
    lookups = [
        force_text(VERBOSE_LOOKUPS.get(lookup, _(lookup)))
        for lookup in lookup_expr.split(LOOKUP_SEP)
    ]

    return ' '.join(lookups) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:27,代码来源:utils.py

示例8: _get_unique_constraints

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _get_unique_constraints(self, instance):
        """Return SQL filter for filtering by fields in ``unique_with`` attribute.

        Filter is returned as tuple of two elements where first one is
        placeholder which is safe to insert into SQL query and second
        one may include potentially dangerous values and must be passed
        to SQL query in ``params`` attribute to make sure it is properly
        escaped.
        """
        constraints_expression = []
        constraints_values = {}
        for field_name in self.unique_with:
            if constants.LOOKUP_SEP in field_name:
                raise NotImplementedError(
                    "`unique_with` constraint does not support lookups by related models."
                )

            field = instance._meta.get_field(field_name)
            field_value = getattr(instance, field_name)

            # Convert value to the database representation.
            field_db_value = field.get_prep_value(field_value)

            constraint_key = "unique_" + field_name
            constraints_expression.append(
                "{} = %({})s".format(
                    connection.ops.quote_name(field.column), constraint_key
                )
            )
            constraints_values[constraint_key] = field_db_value

        if not constraints_expression:
            return "", []

        constraints_expression = "AND " + " AND ".join(constraints_expression)
        return constraints_expression, constraints_values 
开发者ID:genialis,项目名称:resolwe,代码行数:38,代码来源:fields.py

示例9: refs_aggregate

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def refs_aggregate(self, existing_aggregates):
        return refs_aggregate(self.name.split(LOOKUP_SEP), existing_aggregates) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:expressions.py

示例10: find_ordering_name

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def find_ordering_name(self, name, opts, alias=None, default_order='ASC',
                           already_seen=None):
        """
        Returns the table alias (the name might be ambiguous, the alias will
        not be) and column name for ordering by the given 'name' parameter.
        The 'name' is of the form 'field1__field2__...__fieldN'.
        """
        name, order = get_order_dir(name, default_order)
        descending = True if order == 'DESC' else False
        pieces = name.split(LOOKUP_SEP)
        field, targets, alias, joins, path, opts = self._setup_joins(pieces, opts, alias)

        # If we get to this point and the field is a relation to another model,
        # append the default ordering for that model unless the attribute name
        # of the field is specified.
        if field.rel and path and opts.ordering and name != field.attname:
            # Firstly, avoid infinite loops.
            if not already_seen:
                already_seen = set()
            join_tuple = tuple(self.query.alias_map[j].table_name for j in joins)
            if join_tuple in already_seen:
                raise FieldError('Infinite loop caused by ordering.')
            already_seen.add(join_tuple)

            results = []
            for item in opts.ordering:
                results.extend(self.find_ordering_name(item, opts, alias,
                                                       order, already_seen))
            return results
        targets, alias, _ = self.query.trim_joins(targets, joins, path)
        return [(OrderBy(t.get_col(alias), descending=descending), False) for t in targets] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:compiler.py

示例11: _check_geo_field

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _check_geo_field(cls, opts, lookup):
        """
        Utility for checking the given lookup with the given model options.
        The lookup is a string either specifying the geographic field, e.g.
        'point, 'the_geom', or a related lookup on a geographic field like
        'address__point'.

        If a GeometryField exists according to the given lookup on the model
        options, it will be returned.  Otherwise returns None.
        """
        from django.contrib.gis.db.models.fields import GeometryField
        # This takes into account the situation where the lookup is a
        # lookup to a related geographic field, e.g., 'address__point'.
        field_list = lookup.split(LOOKUP_SEP)

        # Reversing so list operates like a queue of related lookups,
        # and popping the top lookup.
        field_list.reverse()
        fld_name = field_list.pop()

        try:
            geo_fld = opts.get_field(fld_name)
            # If the field list is still around, then it means that the
            # lookup was for a geometry field across a relationship --
            # thus we keep on getting the related model options and the
            # model field associated with the next field in the list
            # until there's no more left.
            while len(field_list):
                opts = geo_fld.rel.to._meta
                geo_fld = opts.get_field(field_list.pop())
        except (FieldDoesNotExist, AttributeError):
            return False

        # Finally, make sure we got a Geographic field and return.
        if isinstance(geo_fld, GeometryField):
            return geo_fld
        else:
            return False 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:40,代码来源:lookups.py

示例12: _check_related_query_name_is_valid

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _check_related_query_name_is_valid(self):
        if self.remote_field.is_hidden():
            return []
        rel_query_name = self.related_query_name()
        errors = []
        if rel_query_name.endswith('_'):
            errors.append(
                checks.Error(
                    "Reverse query name '%s' must not end with an underscore."
                    % (rel_query_name,),
                    hint=("Add or change a related_name or related_query_name "
                          "argument for this field."),
                    obj=self,
                    id='fields.E308',
                )
            )
        if LOOKUP_SEP in rel_query_name:
            errors.append(
                checks.Error(
                    "Reverse query name '%s' must not contain '%s'."
                    % (rel_query_name, LOOKUP_SEP),
                    hint=("Add or change a related_name or related_query_name "
                          "argument for this field."),
                    obj=self,
                    id='fields.E309',
                )
            )
        return errors 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:30,代码来源:related.py

示例13: _check_field_name

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _check_field_name(self):
        """
        Check if field name is valid, i.e. 1) does not end with an
        underscore, 2) does not contain "__" and 3) is not "pk".
        """
        if self.name.endswith('_'):
            return [
                checks.Error(
                    'Field names must not end with an underscore.',
                    obj=self,
                    id='fields.E001',
                )
            ]
        elif LOOKUP_SEP in self.name:
            return [
                checks.Error(
                    'Field names must not contain "%s".' % (LOOKUP_SEP,),
                    obj=self,
                    id='fields.E002',
                )
            ]
        elif self.name == 'pk':
            return [
                checks.Error(
                    "'pk' is a reserved word that cannot be used as a field name.",
                    obj=self,
                    id='fields.E003',
                )
            ]
        else:
            return [] 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:33,代码来源:__init__.py

示例14: _check_ordering_item

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def _check_ordering_item(self, obj, model, field_name, label):
        """ Check that `ordering` refers to existing fields. """

        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:reBiocoder,项目名称:bioforum,代码行数:32,代码来源:checks.py

示例15: resolve_expression

# 需要导入模块: from django.db.models import constants [as 别名]
# 或者: from django.db.models.constants import LOOKUP_SEP [as 别名]
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
        rhs = super().resolve_expression(query, allow_joins, reuse, summarize, for_save)

        field_list = self.name.split(LOOKUP_SEP)
        for name in field_list[1:]:
            rhs = KeyTextTransformFactory(name)(rhs)
        return rhs 
开发者ID:aropan,项目名称:clist,代码行数:9,代码来源:json_field.py


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