本文整理匯總了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
示例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