本文整理汇总了Python中django.db.models.sql.query.LOOKUP_SEP.join方法的典型用法代码示例。如果您正苦于以下问题:Python LOOKUP_SEP.join方法的具体用法?Python LOOKUP_SEP.join怎么用?Python LOOKUP_SEP.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.sql.query.LOOKUP_SEP
的用法示例。
在下文中一共展示了LOOKUP_SEP.join方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reverse_field_path
# 需要导入模块: from django.db.models.sql.query import LOOKUP_SEP [as 别名]
# 或者: from django.db.models.sql.query.LOOKUP_SEP import join [as 别名]
def reverse_field_path(model, path):
""" Create a reversed field path.
E.g. Given (Order, "user__groups"),
return (Group, "user__order").
Final field must be a related model, not a data field.
"""
reversed_path = []
parent = model
pieces = path.split(LOOKUP_SEP)
for piece in pieces:
field = parent._meta.get_field(piece)
direct = not field.auto_created or field.concrete
# skip trailing data field if extant:
if len(reversed_path) == len(pieces) - 1: # final iteration
try:
get_model_from_relation(field)
except NotRelationField:
break
if direct:
related_name = field.related_query_name()
parent = field.rel.to
else:
related_name = field.field.name
parent = field.model
reversed_path.insert(0, related_name)
return (parent, LOOKUP_SEP.join(reversed_path))
示例2: as_sql
# 需要导入模块: from django.db.models.sql.query import LOOKUP_SEP [as 别名]
# 或者: from django.db.models.sql.query.LOOKUP_SEP import join [as 别名]
def as_sql(self, qn, connection):
filters = []
for lookup in self.field._subtype_rel_map:
lookup = LOOKUP_SEP.join([lookup] + self.lhs.init_lookups)
filters.append(Q(**{lookup: self.rhs}))
query_expr = reduce(operator.or_, filters)
import ipdb; ipdb.set_trace()
qn.query.add_q(query_expr)
return '', []
示例3: lookup_allowed
# 需要导入模块: from django.db.models.sql.query import LOOKUP_SEP [as 别名]
# 或者: from django.db.models.sql.query.LOOKUP_SEP import join [as 别名]
def lookup_allowed(self, lookup, value):
model = self.model
# Check FKey lookups that are allowed, so that popups produced by
# ForeignKeyRawIdWidget, on the basis of ForeignKey.limit_choices_to,
# are allowed to work.
for l in model._meta.related_fkey_lookups:
for k, v in widgets.url_params_from_lookup_dict(l).items():
if k == lookup and v == value:
return True
parts = lookup.split(LOOKUP_SEP)
# Last term in lookup is a query term (__exact, __startswith etc)
# This term can be ignored.
if len(parts) > 1 and parts[-1] in QUERY_TERMS:
parts.pop()
# Special case -- foo__id__exact and foo__id queries are implied
# if foo has been specificially included in the lookup list; so
# drop __id if it is the last part. However, first we need to find
# the pk attribute name.
rel_name = None
for part in parts[:-1]:
try:
field, _, _, _ = model._meta.get_field_by_name(part)
except FieldDoesNotExist:
# Lookups on non-existants fields are ok, since they're ignored
# later.
return True
if hasattr(field, 'rel'):
model = field.rel.to
rel_name = field.rel.get_related_field().name
elif isinstance(field, RelatedObject):
model = field.model
rel_name = model._meta.pk.name
else:
rel_name = None
if rel_name and len(parts) > 1 and parts[-1] == rel_name:
parts.pop()
if len(parts) == 1:
return True
clean_lookup = LOOKUP_SEP.join(parts)
return clean_lookup in self.list_filter