Here's my code
I'm bulding a database model with flask-sqlalchemy. When doing my inheritances, I used super()__init__(cdata) but python returns an error saying it takes exactly one argument.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/mnt/d/September/bank/app/backoffice/models.py", line 31, in __init__
super().__init__(cdata)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
Here's my code
from app import db
class Customer(db.Model):
__tablename__ = "customer"
id = db.Column(db.Integer, primary_key=True)
fname = db.Column(db.String(32), nullable=False)
lname = db.Column(db.String(32), nullable=False)
customer_type = db.Column(db.String(32))
__mapper_args__ = {
"polymorphic_identity": "customer",
"polymorphic_on": customer_type
}
def __init__(self, **cdata):
self.fname = cdata["fname"]
self.lname = cdata["lname"]
def __repr__(self):
return f"[Customer: {self.fname}]"
class Employee():
__tablename__ = "employee"
id = db.Column(db.Integer, db.ForeignKey("customer.id"), primary_key=True)
title = db.Column(db.String(32), nullable=False)
__mapper_args = {
"polymorphic_identity": "employee"
}
def __init__(self, cdata):
super().__init__(cdata)
Where could I have gone wrong> I have given the required argument, and similar code works elsewhere