I'm trying to define a model whose id
is case-insensitive but case-preserving, and the below nearly works:
class MyModel(endpoints_ndb.EndpointsModel):
_message_fields_schema = ('id', 'name')
caseful_id = ndb.StringProperty(indexed=False)
name = ndb.StringProperty(required=True)
def IdSet(self, value):
if not isinstance(value, basestring):
raise TypeError('ID must be a string.')
self.caseful_id = value
self.UpdateFromKey(ndb.Key(self.__class__, value.lower()))
@endpoints_ndb.EndpointsAliasProperty(setter=IdSet)
def id(self):
return self.caseful_id
Creating a new instance stores the id
in lowercase, with the original capitalisation in caseful_id
, and fetching a list returns the original capitalisations, but requesting a specific model by id
with:
@MyModel.method(request_fields=('id',), path='mymodel/{id}',
http_method='GET', name='mymodel.get')
def MyModelGet(self, mymodel):
if not mymodel.from_datastore:
raise endpoints.NotFoundException('MyModel not found.')
return mymodel
always returns the same id
that was given in the request, with the same capitalisation. Is there a way to make it actually call the id
getter function?