Django inheritance access
As with the most recent version, Django does not allow a subclass to have a variable with the same name as a variable in its superclass if that variable is a field instance.
I need a subclass to change this variable, which I call "department". By calling my super and sub classes, I need sub to modify the department variable that it inherits from super. If I swap it, Django throws a field error. Of course, if I don't, the department cannot reassign. If super doesn't have a department then I get database errors. I get strange behavior when I try to rewrite init :
def __init__(self):
super(theSuperClass, self).__init__()
TypeError: super (type, obj): obj must be an instance or subtype of the type
Does anyone know how to do this?
a source to share
The first parameter super
should be the current class (i.e. the subclass), not the superclass.
Also, you must pass the arguments passed to __init__
. Therefore it should be:
class MySubClass(MySuperClass):
def __init__(self, *args, **kwargs):
super(MySubClass, self).__init__(*args, **kwargs)
a source to share