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


Python Query.get_meta方法代碼示例

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


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

示例1: _get_field

# 需要導入模塊: from django.db.models.sql.query import Query [as 別名]
# 或者: from django.db.models.sql.query.Query import get_meta [as 別名]
def _get_field(model, name):
    # Create a fake query object so we can easily work out what field
    # type we are dealing with
    qs = Query(model)
    parts = name.split(LOOKUP_SEP)

    # The following is borrowed from the innards of Query.add_filter - it strips out __gt, __exact et al.
    num_parts = len(parts)
    if num_parts > 1 and parts[-1] in QUERY_TERMS:
        # Traverse the lookup query to distinguish related fields from
        # lookup types.
        for counter, field_name in enumerate(parts, 1):
            try:
                lookup_field = model._meta.get_field(field_name)
            except FieldDoesNotExist:
                # Not a field. Bail out.
                parts.pop()
                break
            # Unless we're at the end of the list of lookups, let's attempt
            # to continue traversing relations.
            if counter < num_parts:
                try:
                    model = lookup_field.rel.to
                except AttributeError:
                    # Not a related field. Bail out.
                    parts.pop()
                    break

    return qs.names_to_path(parts, qs.get_meta(), True, fail_on_missing=False)[1]
開發者ID:django4life,項目名稱:django-money,代碼行數:31,代碼來源:managers.py

示例2: _get_field

# 需要導入模塊: from django.db.models.sql.query import Query [as 別名]
# 或者: from django.db.models.sql.query.Query import get_meta [as 別名]
def _get_field(model, name):
    if django.VERSION[0] >= 1 and django.VERSION[1] >= 8:
        # Django 1.8+ - can use something like 
        # expression.output_field.get_internal_field() == 'Money..'
        raise NotImplementedError("Django 1.8+ support is not implemented.")

    from django.db.models.fields import FieldDoesNotExist

    # Create a fake query object so we can easily work out what field
    # type we are dealing with
    qs = Query(model)
    opts = qs.get_meta()
    alias = qs.get_initial_alias()

    parts = name.split(LOOKUP_SEP)

    # The following is borrowed from the innards of Query.add_filter - it strips out __gt, __exact et al.
    num_parts = len(parts)
    if num_parts > 1 and parts[-1] in qs.query_terms:
        # Traverse the lookup query to distinguish related fields from
        # lookup types.
        lookup_model = model
        for counter, field_name in enumerate(parts):
            try:
                lookup_field = lookup_model._meta.get_field(field_name)
            except FieldDoesNotExist:
                # Not a field. Bail out.
                parts.pop()
                break
            # Unless we're at the end of the list of lookups, let's attempt
            # to continue traversing relations.
            if (counter + 1) < num_parts:
                try:
                    lookup_model = lookup_field.rel.to
                except AttributeError:
                    # Not a related field. Bail out.
                    parts.pop()
                    break

    if django.VERSION[0] >= 1 and django.VERSION[1] in (6, 7):
        # Django 1.6-1.7
        field = qs.setup_joins(parts, opts, alias)[0]
    else:
        # Django 1.4-1.5
        field = qs.setup_joins(parts, opts, alias, False)[0]

    return field
開發者ID:CloudRunnerInc,項目名稱:django-money,代碼行數:49,代碼來源:managers.py


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