Merge pull request #502 from cookiecutter-flask/fix-293

Support passing custom sets of kwargs when creating a reference column
master
James Curtin 6 years ago committed by GitHub
commit 6fe4eb17f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py

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

Loading…
Cancel
Save