本文整理汇总了Python中django.contrib.admin.ModelAdmin.lookup_allowed方法的典型用法代码示例。如果您正苦于以下问题:Python ModelAdmin.lookup_allowed方法的具体用法?Python ModelAdmin.lookup_allowed怎么用?Python ModelAdmin.lookup_allowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.ModelAdmin
的用法示例。
在下文中一共展示了ModelAdmin.lookup_allowed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lookup_allowed
# 需要导入模块: from django.contrib.admin import ModelAdmin [as 别名]
# 或者: from django.contrib.admin.ModelAdmin import lookup_allowed [as 别名]
def lookup_allowed(self, lookup, value):
# overriden to allow filter on cell_filter fields
# import django.contrib.admin.options
# django.contrib.admin.options.QUERY_TERMS.update({'not':'not'})
original = DjangoModelAdmin.lookup_allowed(self, lookup, value)
if original:
return True
model = self.model
parts = lookup.split(LOOKUP_SEP)
if len(parts) > 1 and parts[-1] in QUERY_TERMS:
parts.pop()
pk_attr_name = None
for part in parts[:-1]:
field, _, _, _ = model._meta.get_field_by_name(part)
if hasattr(field, 'rel'):
model = field.rel.to
pk_attr_name = model._meta.pk.name
elif isinstance(field, RelatedObject):
model = field.model
pk_attr_name = model._meta.pk.name
else:
pk_attr_name = None
if pk_attr_name and len(parts) > 1 and parts[-1] == pk_attr_name:
parts.pop()
clean_lookup = LOOKUP_SEP.join(parts)
flat_filter = [isinstance(v, tuple) and v[0] or v for v in self.list_filter]
flat_filter.extend([isinstance(v, tuple) and v[0] or v for v in self.cell_filter])
return clean_lookup in self.extra_allowed_filter or clean_lookup in flat_filter