Paul's Programming Notes     Archive     Feed     Github

Get ID of edited item within WTforms validator - Flask-Admin

def start_must_not_conflict(form, field):
print request.args.get('id') # get ID
if Event.query.filter(db.and_(Event.location == form.location.data, Event.start.between(form.start.data, form.end.data), Event.id != request.args.get('id'))).first(): # exclude ID from query
raise wtforms.validators.ValidationError('Start time conflicts with another request for the same time.')
form_args = dict(
start=dict(validators=[start_must_not_conflict])
)