Reputation: 8060
I am trying to create a base class where id and url are specified for convenience.
Base = declarative_base()
Base.query = session.query_property()
class CrawlableEntity(Base):
"""CrawlableEntity class for all entities crawled online.
"""
id = Column(Integer, primary_key=True)
url = Column(String, nullable=False)
class Model(CrawlableEntity):
__tablename__ = 'models'
name = Column(String) # Bobby Raffin
looks = relationship('Look', backref='model')
I am getting the following error
sqlalchemy.exc.InvalidRequestError: Class <class 'CrawlableEntity'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
Is this pattern possible in sqlalchemy?
Upvotes: 10
Views: 3984
Reputation: 76962
See Abstract Concrete Classes:
class CrawlableEntity(Base):
"""CrawlableEntity class for all entities crawled online. """
__abstract__ = True
id = Column(Integer, primary_key=True)
url = Column(String, nullable=False)
Upvotes: 15