Navigation Menu

Skip to content

Commit

Permalink
Adding to the example app showing use of custom validators on form
Browse files Browse the repository at this point in the history
fields
  • Loading branch information
coleifer committed May 20, 2012
1 parent 5359f5f commit a26b3c5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion example/app.py
Expand Up @@ -19,6 +19,7 @@

from flask import Flask, redirect, render_template, request, g, abort, url_for, flash
from peewee import *
from wtforms.validators import Length
from wtfpeewee.fields import ModelHiddenField
from wtfpeewee.orm import model_form, ModelConverter

Expand Down Expand Up @@ -77,7 +78,11 @@ class HiddenForeignKeyConverter(ModelConverter):
def handle_foreign_key(self, model, field, **kwargs):
return field.name, ModelHiddenField(model=field.to, **kwargs)

PostForm = model_form(Post)

PostForm = model_form(Post, field_args={
'title': dict(validators=[Length(min=3, max=200)]), # title must be at least 3 chars long
'content': dict(description='this is the body of the post'), # a little help text
})
CommentForm = model_form(Comment, exclude=('pub_date',), converter=HiddenForeignKeyConverter())


Expand Down

0 comments on commit a26b3c5

Please sign in to comment.