I have created a custom Property class,
from google.appengine.ext import db
class UserNotFoundError(Exception):
pass
class User(object):
def __init__(self, user=None, email=None):
if user is None and email is not None:
user = Users.all().filter('email', db.Email(email)).get()
if not user:
raise UserNotFoundError
self.__user = user
self.__permissions = None
class Users(db.Expando):
email = EmailProperty()
class CustomUserProperty(db.Property):
data_type = User
# For writing to datastore.
def get_value_for_datastore(self, model_instance):
# user will be a User object
user = super(CustomUserProperty,
self).get_value_for_datastore(model_instance)
if not user:
return None
return user.user_id()
# For reading from datastore.
def make_value_from_datastore(self, value):
if value is None:
return None
return User( user = Users.get( Key( value ) ) )
And it works for when I insert and do references, but when I attempt
to do something like this..
user = User() # This is for this example, in the code it loads the
proper User
addresses = UserAddress.all().filter('user', user) # Imagine this
has being a class extended from db.Model
It throws an error like:
BadValueError: Unsupported type for property : <class 'User'>
Is there a way to make it so when using filter() or other comparisons
through the db functionality it also converts it to the datastore
value?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.