On Aug 18, 2011, at 6:06 PM, Mark Erbaugh wrote:
> I want to create a table that has several similar fields. For example, assume
> the fields are field1, field2, ...
>
> Is there a way in the declarative class that I can do something like:
>
> for i in range(10):
> 'field%d' % i = Column( ... )
>
Id use a mixin so that a superclass can be generated in a data driven manner:
MyCols = type("MyCols", (object, ), dict(("field%d" % i, Column(Integer)) for i
in xrange(1, 10)))
class MyClass(MyCols, Base):
...
otherwise if you want to go the append_column() route, you can just tack them
on the class, declarative will call append_column() as well as
mapper.add_property():
for name, col in ("field%d" % i, Column(Integer)) for i in xrange(1, 10)):
setattr(MyClass, name, col)
--
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.