|
|
@ -62,7 +62,7 @@ class SurrogatePK(object): |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reference_col(tablename, nullable=False, pk_name='id', **kwargs): |
|
|
|
def reference_col(tablename, nullable=False, pk_name='id', foreign_key_kwargs=None, column_kwargs=None): |
|
|
|
"""Column that adds primary key foreign key reference. |
|
|
|
"""Column that adds primary key foreign key reference. |
|
|
|
|
|
|
|
|
|
|
|
Usage: :: |
|
|
|
Usage: :: |
|
|
@ -70,6 +70,9 @@ def reference_col(tablename, nullable=False, pk_name='id', **kwargs): |
|
|
|
category_id = reference_col('category') |
|
|
|
category_id = reference_col('category') |
|
|
|
category = relationship('Category', backref='categories') |
|
|
|
category = relationship('Category', backref='categories') |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
foreign_key_kwargs = foreign_key_kwargs or {} |
|
|
|
|
|
|
|
column_kwargs = column_kwargs or {} |
|
|
|
|
|
|
|
|
|
|
|
return Column( |
|
|
|
return Column( |
|
|
|
db.ForeignKey('{0}.{1}'.format(tablename, pk_name)), |
|
|
|
db.ForeignKey('{0}.{1}'.format(tablename, pk_name), **foreign_key_kwargs), |
|
|
|
nullable=nullable, **kwargs) |
|
|
|
nullable=nullable, **column_kwargs) |
|
|
|