Support passing custom sets of kwargs when creating a reference column

master
James Curtin 6 years ago
parent 5d7f8ab303
commit c561980bef
No known key found for this signature in database
GPG Key ID: E33439C11796824D
  1. 11
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py

@ -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,11 @@ 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')
""" """
if foreign_key_kwargs is None:
foreign_key_kwargs = {}
if column_kwargs is None:
column_kwargs = {}
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)

Loading…
Cancel
Save