所以我有一个基于ndb.Model
from google.appengine.ext import ndb
class CFCSocialUser(ndb.Model):
def clean_dob(self, value):
if value.year < 1900:
raise Exception("Year cannot be less than 1900")
username = ndb.StringProperty(required=True)
userid = ndb.IntegerProperty()
email = ndb.StringProperty(required=True)
date_of_birth = ndb.DateProperty(validator=clean_dob)
@staticmethod
def create_new_user(name, email, date_of_birth):
app = CFCSocialUser(username=name,
email=email,
date_of_birth=date_of_birth,
id=name)
return app.put()
@staticmethod
def create_new_user_id(name, email, date_of_birth, id):
app = CFCSocialUser(username=name,
email=email,
date_of_birth=date_of_birth,
key=id)
return app.put()
我有另一个基于ndb.Model
的模型,看起来像
from google.appengine.ext import ndb
from mainsite.rainbow.models.CFCSocialUser import CFCSocialUser
class CFCSocialGroup(ndb.Model):
name = ndb.StringProperty(required=True)
created_on = ndb.StringProperty()
created_by = CFCSocialUser()
members = CFCSocialUser(repeated=True)
如何使用members
功能向CFCSocialGroup
的{{1}}属性添加验证器,例如CFCSocialUser
中的出生日期属性验证器?
验证器将确保重复的CFCSocialUsers不属于同一组。