So I have a model based on 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()
I have another model based on ndb.Model
, which looks like
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)
How do I add a validator to the members
property of CFCSocialGroup
, like I validator for the date of birth property in CFCSocialUser
using the clean_dob
function?
The validator will ensure that duplicate CFCSocialUsers are not part of the same group.