1

无论我尝试了什么,对于我简单的 OneToMany 关系,我都无法使用请求处理程序解决递归问题,比如说父亲 1 : N Sons

FatherHandler 应在其结果集中返回 sons_set(儿子列表)。SonHandler 应在结果集中返回父对象。

由于字段,排除,设置似乎静态绑定到处理程序(以及背后的模型),似乎不可能动态更改要返回的字段,我总是以递归结束。(例如,当从 SonHandler 调用时,我确实尝试从字段列表中排除 sons_set,但最初的 FatherHandler 设置似乎仍然有效)

class FatherHandler(GenericHandler):
    model = Father
    exclude = () # to also show 'id' field
    fields = ('id', 'name', ('son_set', ('id', 'name')))
    allowed_methods = ('GET', 'POST', 'PUT')

class SonHandler(GenericHandler):
    model = Son
    exclude = () # to also show 'id' field
    fields = ('id', 'name', ('father', ('id', 'name')))
    allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')

    def read(self, request, key=None):
        FatherHandler.exclude = ('son_set')
        # does not work ...
4

0 回答 0