CONTINUING ! sorry
On Fri, Oct 20, 2017 at 11:55 AM, Sven Dumay <sven.du...@gmail.com> wrote: > > *I tried other things and I found the following solution :* > > from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta > from sqlalchemy import Column, Integer > > class MetaBase(DeclarativeMeta): > > def __init__(cls, nom, bases, contenu): > super(MetaBase, cls).__init__(nom, bases, contenu) > print("Init MetaBase") > > Base = declarative_base(metaclass = MetaBase) > > class Stockable(Base): > > __abstract__ = True > > def __init__(self): > print("Init Stockable") > > class Character(Stockable): > > __tablename__ = 'characters' > id = Column(Integer, primary_key=True) > > def __init__(self, name): > self.name = name > print("Init character") > > > jean = Character("Jean") > print(jean.name) > > > this seems like roughly the correct approach. > It seems to work. I get the following result : > > >>> > Init MetaBase > Init MetaBase > Init MetaBase > Init compte > Jean > >>> > > However, the problem with this method is that I have to add *"__abstract__ > = True" *to every class which is inherited by Stockable... so, about 400 > classes. > I don't see why that is. If these classes are mapped to tables (which, if they are persisted, they are), then there is no reason to add "__abstract__". As in my previous email, how these 400 classes link to tables is what needs to be answered and then we can formulate the correct calling style. > It is not very clean. Is it possible to avoid that by using something > similar to my first code ? It would be great ! > > Thank you very much. > > Sven > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.