def column(self, coltype, name, **kwargs):
"""
Generic method to add a column of any type.
:param coltype: Column type (from FIELD_TO_PEEWEE).
:param name: Name of column.
:param kwargs: Arguments for the given column type.
"""
constraints = kwargs.pop('constraints', [])
new_constraints = []
for const in constraints:
if isinstance(const, str):
const = peewee.SQL(const)
new_constraints.append(const)
kwargs['constraints'] = new_constraints
field_class = FIELD_TO_PEEWEE.get(coltype, peewee.CharField)
field_class(**kwargs).add_to_class(self.model, name)
评论列表
文章目录