本文整理汇总了Python中tastypie.bundle.Bundle.data[field_name]方法的典型用法代码示例。如果您正苦于以下问题:Python Bundle.data[field_name]方法的具体用法?Python Bundle.data[field_name]怎么用?Python Bundle.data[field_name]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.bundle.Bundle
的用法示例。
在下文中一共展示了Bundle.data[field_name]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: full_dehydrate
# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import data[field_name] [as 别名]
def full_dehydrate(self, obj):
"""
Given an object instance, extract the information from it to populate
the resource.
"""
bundle = Bundle(obj=obj)
# Dehydrate each field.
for field_name, field_object in self.fields.items():
# A touch leaky but it makes URI resolution work.
if isinstance(field_object, RelatedField):
field_object.api_name = self._meta.api_name
field_object.resource_name = self._meta.resource_name
bundle.data[field_name] = field_object.dehydrate(bundle)
# Run through optional overrides.
for field_name, field_object in self.fields.items():
method = getattr(self, "dehydrate_%s" % field_name, None)
if method:
bundle.data[field_name] = method(bundle)
bundle = self.dehydrate(bundle)
return bundle
示例2: dehydrate
# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import data[field_name] [as 别名]
def dehydrate(self, bundle):
if self.attribute is not None:
obj = getattr(bundle.obj, self.attribute)
final_fields = _get_fields(obj)
schema = obj.schema()
# Run through the list and dehydrate each item
obj_data = {}
for key, item in obj.iteritems():
obj_bundle = Bundle(item)
for field_name, field_object in final_fields.iteritems():
obj_bundle.data[field_name] = field_object.dehydrate(obj_bundle)
obj_data[key] = obj_bundle.data
return self.convert(obj_data)
if self.has_default():
return self.convert(self.default)
else:
return None