gpt4 book ai didi

plone - 在 Dexterity 中使用 z3c.relationfield 进行反向引用

转载 作者:行者123 更新时间:2023-12-01 15:30:53 25 4
gpt4 key购买 nike

使用 z3c.relationfield.schema.RelationList 或 RelationChoice 可以维护与其他 Dexterity 内容对象的关系。在原型(prototype)中,我们有一个功能上下文。 getBRefs() 以检索引用当前“上下文”对象的对象列表。 z3c.relationfield 或 Dexterity 中有类似的东西吗?在 Dexterity 中获取“反向引用”的规范方法是什么?

最佳答案

以下代码摘自

http://code.google.com/p/dexterity/issues/detail?id=234

正在工作:

from Acquisition import aq_inner
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from zope.security import checkPermission
from zc.relation.interfaces import ICatalog


def back_references(source_object, attribute_name):
""" Return back references from source object on specified attribute_name """
catalog = getUtility(ICatalog)
intids = getUtility(IIntIds)
result = []
for rel in catalog.findRelations(
dict(to_id=intids.getId(aq_inner(source_object)),
from_attribute=attribute_name)
):
obj = intids.queryObject(rel.from_id)
if obj is not None and checkPermission('zope2.View', obj):
result.append(obj)
return result

关于plone - 在 Dexterity 中使用 z3c.relationfield 进行反向引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11878341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com