On Aug 18, 2011, at 7:01 PM, Mark Erbaugh wrote:

> 
> On Aug 18, 2011, at 6:06 PM, Mark Erbaugh wrote:
> 
>> 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( ... )
>> 
>> 
>> Thanks,
>> Mark
> 
> 
> Figured it out:
> 
> after the class definition:
> 
> for i in range(10):
>       <class>.__table__.append_column(Column('field%d' % i, ...))


I guess not: while the above code adds the fields to the database table, it 
doesn't add them as named data members of the class.  Here's my latest effort:

class Preferences:
        ...

for i in range(10):
        setattr(Preferences, 'field%d' % i, Column(...

This also answers my question about relationships

        setattr(Preferences 'relationship%d' % i, relationship(...


Mark

-- 
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