Skip to content

Instantly share code, notes, and snippets.

@mhluongo
Created April 30, 2012 20:33
Show Gist options
  • Save mhluongo/2562448 to your computer and use it in GitHub Desktop.
Save mhluongo/2562448 to your computer and use it in GitHub Desktop.
A quick hack for lazy-loaded nodes and relationships using neo4jrestclient (as of 12/2012).
class LazyBase(object):
"""
A mixin to make elements of the REST client lazy.
"""
def __init__(self, url, dic):
self._dont_update = True
super(LazyBase, self).__init__(url, create=False)
self._dic = dic.copy()
self._dont_update = False
def update(self, *args, **kwargs):
if not self._dont_update:
super(LazyBase, self).update(*args,**kwargs)
@classmethod
def from_dict(cls, dic):
return cls(dic['self'], dic)
class LazyNode(LazyBase, neo4j.Node):
id_url_template = 'node/%d'
class LazyRelationship(LazyBase, neo4j.Relationship):
id_url_template = 'relationship/%d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment