本文整理汇总了Python中tastypie.resources.ModelResource.obj_create方法的典型用法代码示例。如果您正苦于以下问题:Python ModelResource.obj_create方法的具体用法?Python ModelResource.obj_create怎么用?Python ModelResource.obj_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.resources.ModelResource
的用法示例。
在下文中一共展示了ModelResource.obj_create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: obj_create
# 需要导入模块: from tastypie.resources import ModelResource [as 别名]
# 或者: from tastypie.resources.ModelResource import obj_create [as 别名]
def obj_create(self, bundle, **kwargs):
try:
return ModelResource.obj_create(self, bundle, **kwargs)
except IntegrityError:
# This has the negative side-effect of always making the server
# respond with (201) regardless of whether or not the object was
# just created. It would be better if it could return (200) if the
# object already existed.
allocation_id = simplejson.loads(bundle.request.body)['allocation_id']
fileset = models.Fileset.objects.get(allocation_id=allocation_id)
bundle.obj = fileset
return bundle