Skip to content

Instantly share code, notes, and snippets.

@dylanvee
Created August 20, 2012 23:27
Show Gist options
  • Save dylanvee/3409230 to your computer and use it in GitHub Desktop.
Save dylanvee/3409230 to your computer and use it in GitHub Desktop.
ndb reference property
from google.appengine.ext import ndb
class ReferenceProperty(ndb.KeyProperty):
def _validate(self, value):
if not isinstance(value, ndb.Model):
raise TypeError('expected an ndb.Model, got %s' % repr(value))
def _to_base_type(self, value):
return value.key
def _from_base_type(self, value):
return value.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment