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


Python query.LOOKUP_SEP屬性代碼示例

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


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

示例1: __init__

# 需要導入模塊: from django.db.models.sql import query [as 別名]
# 或者: from django.db.models.sql.query import LOOKUP_SEP [as 別名]
def __init__(self, admin_view, lookup, value):
        self.admin_view = admin_view
        self.org_model = admin_view.model
        self.opts = admin_view.opts
        self.lookup = lookup
        self.value = value

        parts = lookup.split(LOOKUP_SEP)
        field = self.opts.get_field(parts[0])

        if not is_related_field2(field):
            raise Exception(u'Relate Lookup field must a related field')

        self.to_model = field.related_model
        self.rel_name = '__'.join(parts[1:])
        self.is_m2m = bool(field.many_to_many)

        to_qs = self.to_model._default_manager.get_queryset()
        self.to_objs = to_qs.filter(**{self.rel_name: value}).all()

        self.field = field 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:23,代碼來源:relate.py

示例2: __init__

# 需要導入模塊: from django.db.models.sql import query [as 別名]
# 或者: from django.db.models.sql.query import LOOKUP_SEP [as 別名]
def __init__(self, admin_view, lookup, value):
        self.admin_view = admin_view
        self.org_model = admin_view.model
        self.opts = admin_view.opts
        self.lookup = lookup
        self.value = value

        parts = lookup.split(LOOKUP_SEP)
        field = self.opts.get_field_by_name(parts[0])[0]

        if not hasattr(field, 'rel') and not isinstance(field, ForeignObjectRel):
            raise Exception(u'Relate Lookup field must a related field')

        if hasattr(field, 'rel'):
            self.to_model = field.rel.to
            self.rel_name = field.rel.get_related_field().name
            self.is_m2m = isinstance(field.rel, models.ManyToManyRel)
        else:
            self.to_model = field.model
            self.rel_name = self.to_model._meta.pk.name
            self.is_m2m = False

        to_qs = self.to_model._default_manager.get_queryset()
        self.to_objs = to_qs.filter(**{self.rel_name: value}).all()

        self.field = field 
開發者ID:madre,項目名稱:devops,代碼行數:28,代碼來源:relate.py


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