On Jul 25, 2012, at 4:29 PM, Stephan Hügel wrote:

> 
>  OK, I've done the following
> 
> def create_signlist(sl):
>     class SignList(db.Model):
> 
>         __tablename__ = listname.lower()
>  
>         id = db.Column("id", db.Integer(), primary_key=True)
>         reference = db.Column(db.String(50), nullable=False, unique=True)
> 
>         def __init__(self, reference):
>             self.reference = reference
> 
>     SignList.__name__ = listname
>     return SignList
> 
> signlists = ['lka', 'kal']
> for s in signlists:
>     create_signlists(s)
> 
> But this gives me a warning:
> 
> SAWarning: The classname 'SignList' is already in the registry of this 
> declarative base, mapped to <class 'glyph.models.lka'>
>   _as_declarative(cls, classname, cls.__dict__)

that's only a warning, you can ignore it.   It means if you have some class 
which makes a relationship() to "SignList" using just the name, you won't get 
this new class.

if you want to make a new class that has a new name from the start, use type():

def __init__(self, reference):
    self.reference = reference

d = dict(
        __tablename__ = listname.lower()

        id = db.Column("id", db.Integer(), primary_key=True)
        reference = db.Column(db.String(50), nullable=False, unique=True)

        __init__ = __init__
)
my_class = type(listname, (db.Model,), d)


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to