Created
October 1, 2011 04:29
-
-
Save torufurukawa/1255594 to your computer and use it in GitHub Desktop.
App Engine's ReferenceProperty that does not raise ReferencePropertyResolveError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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