def validate(model, field):
"""Decorator to add validation methods to validation_fields dictionary.
Populate validation_fields dictionary. The key/value pair is made up of
the model (table) name and tuples field name and the method to run.
For example,
{'table_1': [('field_1', 'method_1'), ('field_2', 'method_2'), ...],
'table_A': [('field_a', 'method_a'), ('field_b', 'method_b'), ...],
}
Parameters
----------
field : str
model : str
"""
def _validate(validation_method):
try:
validate.validation_fields[model].append(
(field, validation_method.__name__))
except AttributeError:
validate.validation_fields = defaultdict(list)
validate.validation_fields[model].append(
(field, validation_method.__name__))
@wraps(validation_method)
def wrapped(self):
return validation_method(self)
return wrapped
return _validate
#####################
# Extend peewee Model
#####################
评论列表
文章目录