Skip to content

Instantly share code, notes, and snippets.

@pawl
Created June 2, 2014 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawl/b95ca0f5dc50c4f1995a to your computer and use it in GitHub Desktop.
Save pawl/b95ca0f5dc50c4f1995a to your computer and use it in GitHub Desktop.
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])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment