The chapter illustrates how to define entities and set up an entity manager.
First, we define the entity (document) class.
from tori.db.entity import entity
# Alternatively, @entity('name_of_collection') is to set the name of the collection.
@entity
class Character(object):
def __init__(self, name):
self.name = name
where an entity of class Character automatically has a readable and writable property id which can be set only once.
Warning
It is not recommended to the ID manually. Leave setting the ID to the backend database.
Then, define the entity manager.
from pymongo import MongoClient
from tori.db.manager import Manager
connection = MongoClient()
entity_manager = Manager('default', connection)