Subclass of Django Model Not Accessible from Superclass

272 Views Asked by At

I'm trying to create an inherited model in Django like that below. I should be able to call, for an instance superclass = Superclass(), I should be able to call superclass.subclass, and access the requisite fields. When I do that, I'm told that '1 argument was expected, and 8 were given': any idea where I'm going wrong?

class Superclass(models.Model):
        pass

class Subclass(Superclass):
        def __init__(self):
                super(Subclass, self).__init__()
1

There are 1 best solutions below

0
On BEST ANSWER

The problem here is that you need *args and **kwargs in the subclass constructor and superclass constructor. These two fields will take in the arguments and objects: these include the field information for the superclass, as well as the object manager, among other things. This should do the trick:

class Subclass(Superclass):
    def __init__(self, *args, **kwargs):
            super(Subclass, self).__init__(*args, **kwargs)