joetsuihk
joetsuihk

Reputation: 534

appengine: how to use validator in Class:Property?

described in http://code.google.com/intl/en/appengine/docs/python/datastore/propertyclass.html#Property

but there is no example code.

i code sth like:

class Model(db.Model):
  email = db.EmailProperty(validator=clean_email)

  def clean_email(self,value):
    if ...

Upvotes: 0

Views: 936

Answers (2)

Nick Johnson
Nick Johnson

Reputation: 101149

You need to either define the method before the property, as joetsuihk demonstrates, or define it as a function, outside the class. I would recommend the latter, as there's no reason for the validator to be associated with the class.

Upvotes: 1

joetsuihk
joetsuihk

Reputation: 534

class Model(db.Model):

  def clean_email(value):
    if ...

  email = db.EmailProperty(validator=clean_email)

use a argument. and the argument itself is the value of email in this case.

Upvotes: 2

Related Questions