Get ID of edited item within WTforms validator - Flask-Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | |
) |