本文整理汇总了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