Django tastypie,如何访问ModelResource类中post_list创建的对象

时间:2014-11-06 10:59:59

标签: django python-2.7 tastypie

这是我的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来获取对象..?

1 个答案:

答案 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