Created
June 2, 2014 03:03
-
-
Save pawl/b95ca0f5dc50c4f1995a to your computer and use it in GitHub Desktop.
Get ID of edited item within WTforms validator - Flask-Admin
This file contains hidden or 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]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment