Skip to content

Instantly share code, notes, and snippets.

@maciekrb
Created April 10, 2014 22:00
Show Gist options
  • Save maciekrb/10427469 to your computer and use it in GitHub Desktop.
Save maciekrb/10427469 to your computer and use it in GitHub Desktop.
class VariableGroup(EndpointsModel):
_message_fields_schema = ('name', 'id', 'tags', 'identifier')
acl = ndb.StructuredProperty(AclRule)
tag_keys = ndb.KeyProperty(kind='Tag', repeated=True)
group_id = ndb.StringProperty()
name = ndb.StringProperty()
@property
def identifier(self):
if self.group_id is None:
self.group_id = int(random.random() * 10000)
return "vgroup_{}".format(self.group_id)
@EndpointsAliasProperty(repeated=True, property_type=Tag.ProtoModel())
def tags(self):
if self.tag_keys:
return ndb.get_multi(self.tag_keys)
class Variable(EndpointsModel):
_message_fields_schema = ('value', 'id', 'groupid')
acl = ndb.StructuredProperty(AclRule)
group_key = ndb.KeyProperty(kind='VariableGroup')
value = ndb.GenericProperty()
@EndpointsAliasProperty(repeated=True, property_type=Tag.ProtoModel())
def groupid(self):
return self.group_key.id()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment