I have class which inherits from 2 classes, but in child class instance I cant access second parent's instance attribute, here is my code example
class Parent1:
def __init__(self):
self.a = 'a'
class Parent2:
def __init__(self):
self.b = 'b'
class Child(Parent1, Parent2):
pass
instance = Child()
print(instance.a)
print(instance.b) # here is error
is there actually clean way around?.
P.S: What i am actually doing is in django. In views I want to put extra parent class which will add some attributes to the view class instance
class ContextMixin:
def __init__(self):
self.context = {
'data': None,
'message': None
}
# and in all/some views do like that
class LoginView(APIView, ContextMixin):
def post(self, request):
# use self.context instead of creating each time
pass