这是我的tastypie代码段。
class MycustomeResource(ModelResource):
asdf = fields.IntegerField('asdf', null=True)
adsfasd = fields.IntegerField('adsfasd')
class Meta:
always_return_data = True
queryset = Mycustome.objects.all()
def post_list(self, request, **kwargs):
object_temp = super(MycustomeResource, self).post_list(request, **kwargs)
return object_temp
这里post_list
正在创建对象,我想要那个对象,以便我可以对它进行操作。
我是否需要覆盖obj_create
来获取对象..?
答案 0 :(得分:2)
是的,post_list方法调用ModelResource类的obj_create方法,你可以像这样访问你的对象:
def obj_create(self, bundle, request=None, **kwargs):
bundle = super(MycustomeResource, self).obj_create(bundle, request)
'''
operations with your object bundle.obj
'''
return bundle