Re: [SQLObject] two beginner's questions
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Frank B. <fb...@fo...> - 2003-04-28 21:09:05
|
Hallo,
Bud P.Bruegger hat gesagt: // Bud P.Bruegger wrote:
> 2. is there a way to control redundancy in the following example:
>
> class test1 (SQLObject):
> _columns = [StringCol("lang", lenght=2, default='en'),
> IntCol("someOtherStuffHere")]
>
> class test2 (SQLObject):
> _columns = [StringCol("lang", lenght=2, default='en'),
> StringCol("differentStuffThanInTest1")]
>
> I would like to decide only once how to represent a language in the
> DBMS and use this consistently in various class definitions.
>
> I unsuccessfully tried to define a StringCol object, langCol, before
> and use it in the _columns definition. This does not seem to work if
> I use it in more than one class though.
What about this:
class Lang (SQLObject):
_columns = [StringCol("lang", length=2, unique=1)]
class test1 (SQLObject):
_columns = [IntCol("langID", foreignKey="Lang"),
IntCol("some")]
class test2 (SQLObject):
_columns = [IntCol("langID", foreignKey="Lang"),
StringCol("different")]
en = Lang.new(lang="en")
t1 = test1.new(langID=en.id, some=1)
t2 = test2.new(langID=en.id, different="foo")
print t1.lang
print t2.lang
ciao
--
Frank Barknecht _ ______footils.org__
|