这是我的Tastype代码片段。在
我有一个资源,在post_list
方法中,Mysample
的一个实例正在那里创建。在
我想调用一个Mysample
实例的方法,请帮助我怎么做
请在我需要调用Mysample
实例的方法的代码中找到注释
class MysampleResource(ModelResource):
intfeild1 = fields.IntegerField('intfeild1_id', null=True)
intfeild2 = fields.IntegerField('intfeild1_id')
class Meta:
always_return_data = True
queryset = Mysample.objects.all()
allowed_methods = ['get','post','put','delete',]
authentication = SessionAuthentication()
authorization = MysampleAuthorization()
def post_list(self, request, **kwargs):
result = super(MysampleResource, self).post_list(request, **kwargs)
#here I want to call a method of Mysample Instance.
return result
请帮帮我,我是乞丐,所以你能给我建议,哪种方法可以覆盖,我应该在哪里这样做。在
您只需在资源中添加方法:
在post_列表中,您可以将其称为:
^{pr2}$注意:方法声明包含2个参数,但在python中,“self”作为隐式参数传递,这样当您调用方法时,不会传递self对象。在
如果我们应用前面的所有概念,您的代码应该如下所示:
相关问题 更多 >
编程相关推荐