I have a parent class BaseResource
in which I define a behavior that should be common to all child. I am overwriting ModelResource.update_in_place
which is defined in some django-tastypie model.
class BaseResource(ModelResource):
def update_in_place(self, ...):
...
return super(ChildResource, self).update_in_place(...)
Now I have Child1Resource
, Child2Resource
which both inherit from BaseResource
. How can I get the type of the child resource inside of the parent ?
I've tried self.__class__()
, but I get must be type, not Child1Resource
.
You would need self.__class__
, not self.__class__()
(the parens are the call operator, so the later returns a self.__class__
instance, not the class itself.
But anyway: that's not how to use super()
, you really want to pass BaseResource
as the first argument here - the whole point being to pass the class where the method is defined, not the class on which the method is called (which would be pointless since it can be inspected using self.__class__
).