Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv22955/SQLObject
Modified Files:
Col.py Style.py
Log Message:
ForeignKey class that is easier to specify
Index: Col.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** Col.py 12 May 2003 01:15:16 -0000 1.20
--- Col.py 12 May 2003 01:58:21 -0000 1.21
***************
*** 257,261 ****
--- 257,281 ----
class KeyCol(Col):
+
baseClass = SOKeyCol
+
+ class SOForeignKey(SOKeyCol):
+
+ def __init__(self, **kw):
+ foreignKey = kw['foreignKey']
+ style = kw['soClass']._style
+ if not kw.get('name'):
+ kw['name'] = style.instanceAttrToIDAttr(style.pythonClassToAttr(foreignKey))
+ else:
+ if not kw['name'].upper().endswith('ID'):
+ kw['name'] = style.instanceAttrToIDAttr(kw['name'])
+ SOKeyCol.__init__(self, **kw)
+
+ class ForeignKey(KeyCol):
+
+ baseClass = SOForeignKey
+
+ def __init__(self, foreignKey=None, **kw):
+ KeyCol.__init__(self, foreignKey=foreignKey, **kw)
class SOEnumCol(SOCol):
Index: Style.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Style.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Style.py 5 May 2003 17:55:48 -0000 1.2
--- Style.py 12 May 2003 01:58:21 -0000 1.3
***************
*** 43,46 ****
--- 43,54 ----
return 'id'
+ def pythonClassToAttr(self, className):
+ return className[0].lower() + className[1:]
+
+ def instanceAttrToIDAttr(self, attr):
+ # @@: Right now, because of how names are created for foreign
+ # keys, you can't really change this style.
+ return attr + "ID"
+
class MixedCaseUnderscoreStyle(Style):
|