2014-11-06 32 views
0

这里是我的tastypie代码片段。Django tastypie,如何访问由ModelResource类中的post_list创建的对象

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才能获得对象..?

回答

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 
+0

好的,谢谢你,在这里写这篇obj_create功能? – RMK 2014-11-07 03:27:17

+0

在您的modelResource中。 – 2014-11-07 10:30:45

相关问题