当前位置: 首页>>代码示例>>Python>>正文


Python Bundle.depth方法代码示例

本文整理汇总了Python中tastypie.bundle.Bundle.depth方法的典型用法代码示例。如果您正苦于以下问题:Python Bundle.depth方法的具体用法?Python Bundle.depth怎么用?Python Bundle.depth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tastypie.bundle.Bundle的用法示例。


在下文中一共展示了Bundle.depth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dehydrate

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import depth [as 别名]
    def dehydrate(self, bundle):
        foreign_obj = None

        if isinstance(self.attribute, basestring):
            attrs = self.attribute.split('__')
            foreign_obj = bundle.obj

            for attr in attrs:
                previous_obj = foreign_obj
                try:
                    foreign_obj = getattr(foreign_obj, attr, None)
                except ObjectDoesNotExist:
                    foreign_obj = None
        elif callable(self.attribute):
            foreign_obj = self.attribute(bundle)

        if not foreign_obj:
            if not self.null:
                raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, attr))

            return None
        

        self.fk_resource = self.get_related_resource(foreign_obj)
        fk_bundle = Bundle(obj=foreign_obj, request=bundle.request)
        depth = getattr(bundle, 'depth', None)
        if depth is None:
            depth = self.max_depth
        if depth is not None:
            fk_bundle.depth = depth - 1
        return self.dehydrate_related(fk_bundle, self.fk_resource)
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:33,代码来源:fields.py

示例2: dehydrate

# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import depth [as 别名]
    def dehydrate(self, bundle, for_list=True):
        foreign_obj = None

        if callable(self.attribute):
            previous_obj = bundle.obj
            foreign_obj = self.attribute(bundle)
        elif isinstance(self.attribute, six.string_types):
            foreign_obj = bundle.obj

            for attr in self._attrs:
                previous_obj = foreign_obj
                try:
                    foreign_obj = getattr(foreign_obj, attr, None)
                except ObjectDoesNotExist:
                    foreign_obj = None

        if not foreign_obj:
            if not self.null:
                if callable(self.attribute):
                    raise ApiFieldError("The related resource for resource %s could not be found." % (previous_obj))
                else:
                    raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, attr))
            return None

        fk_resource = self.get_related_resource(foreign_obj)
        fk_bundle = Bundle(obj=foreign_obj, request=bundle.request)
        fk_bundle.fields = getattr(bundle, 'fields', None)
        depth = getattr(bundle, 'depth', None)
        if depth is None:
            depth = self.max_depth
        if depth is not None:
            fk_bundle.depth = depth - 1
        return self.dehydrate_related(fk_bundle, fk_resource, for_list=for_list)
开发者ID:alecoutre,项目名称:django-tastypie,代码行数:35,代码来源:fields.py


注:本文中的tastypie.bundle.Bundle.depth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。