Skip to content

Instantly share code, notes, and snippets.

@torufurukawa
Created October 1, 2011 04:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torufurukawa/1255594 to your computer and use it in GitHub Desktop.
Save torufurukawa/1255594 to your computer and use it in GitHub Desktop.
App Engine's ReferenceProperty that does not raise ReferencePropertyResolveError.
from google.appengine.ext import db
class ReferenceProperty(db.ReferenceProperty):
"""A property that represents a many-to-one reference to another model.
This acts as identical to google.appengine.ext.db.ReferenceProperty,
except objects returns None when referenced entity does not exist
instead of raising ReferencePropertyResolveError.
"""
def __get__(self, *args, **kw):
try:
return super(ReferenceProperty, self).__get__(*args, **kw)
except db.ReferencePropertyResolveError:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment