本文整理汇总了Python中django.contrib.admin.util.NestedObjects.instances_with_model方法的典型用法代码示例。如果您正苦于以下问题:Python NestedObjects.instances_with_model方法的具体用法?Python NestedObjects.instances_with_model怎么用?Python NestedObjects.instances_with_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.util.NestedObjects
的用法示例。
在下文中一共展示了NestedObjects.instances_with_model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: related_not_authorized
# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import instances_with_model [as 别名]
def related_not_authorized(self, user, objs):
"""
Find all objects related to ``objs`` that should also be deleted. ``objs``
must be a homogenous iterable of objects (e.g. a QuerySet).
"""
collector = NestedObjects(using=DEFAULT_DB_ALIAS)
collector.collect(objs)
blocked = []
for model, obj in collector.instances_with_model():
admin_instance = admin.site._registry.get(obj.__class__, None)
if admin_instance and hasattr(admin_instance, 'is_authorized'):
if not admin_instance.is_authorized(user, obj):
blocked += [obj]
return blocked
示例2: get_related_objects
# 需要导入模块: from django.contrib.admin.util import NestedObjects [as 别名]
# 或者: from django.contrib.admin.util.NestedObjects import instances_with_model [as 别名]
def get_related_objects(obj):
collector = NestedObjects(using='default')
collector.collect(obj)
return [(model._meta.verbose_name_plural, instance)
for model, instance in collector.instances_with_model()]