2014-11-06 57 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

相關問題