You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB
Python

from neomodel import StructuredNode, StringProperty, RelationshipTo, RelationshipFrom, \
UniqueIdProperty, DateProperty, StructuredRel, RelationshipManager
from neomodel.cardinality import ZeroOrOne, ZeroOrMore, One, OneOrMore
class Jsonifiable(object):
def json(self, include_relations=True):
json = dict()
for name, value in vars(self).items():
if name == 'id':
continue
if isinstance(value, RelationshipManager):
if not include_relations:
continue
if isinstance(value, (One, ZeroOrOne)):
val = value.get_or_none()
print(val)
json[name] = val.json(include_relations=False) if val else None
elif isinstance(value, (OneOrMore, ZeroOrMore)):
json[name] = [val.json(include_relations=False) for val in value.all()]
else:
json[name] = value
return json
class VisitRel(StructuredRel, Jsonifiable):
title = StringProperty(required=True)
description = StringProperty()
date = DateProperty()
class Person(StructuredNode, Jsonifiable):
uid = UniqueIdProperty()
name = StringProperty(required=True)
father = RelationshipTo('Person', 'FATHER', cardinality=ZeroOrOne)
mother = RelationshipTo('Person', 'MOTHER', cardinality=ZeroOrOne)
birthdate = DateProperty()
deceased = DateProperty()
description = StringProperty()
picture = StringProperty()
places = RelationshipTo('Place', 'VISITOR', ZeroOrMore, model=VisitRel)
class Event(StructuredNode, Jsonifiable):
uid = UniqueIdProperty()
name = StringProperty(required=True)
participants = RelationshipTo(Person, 'PARTICIPANT', cardinality=ZeroOrMore)
places = RelationshipTo('Place', 'HAPPENED_AT', cardinality=ZeroOrMore)
date = DateProperty()
end_date = DateProperty()
related_events = RelationshipTo('Event', 'RELATED_EVENT')
class Place(StructuredNode, Jsonifiable):
uid = UniqueIdProperty()
name = StringProperty(required=True)
description = StringProperty()
visitors = RelationshipFrom(Person, 'VISITOR', ZeroOrMore, model=VisitRel)
class Image(StructuredNode, Jsonifiable):
uid = StringProperty(unique_index=True, required=True)
description = StringProperty()
pictured = RelationshipTo(Person, 'PICTURED')
place = RelationshipTo(Place, 'TAKEN_AT')
date = DateProperty()