Package snakelegs :: Module document :: Class Document
[hide private]
[frames] | no frames]

Class Document

object --+
         |
        Document
Known Subclasses:

Base class for all models. Classes inheritiing this one should include instances of the BaseField. This class implements reasonable defaults for each method, but these can be overriden by subclasses

Instance Methods [hide private]
 
__init__(self, **kwargs)
By default, stores everything from kwargs into self as an attribute with the same name
 
__str__(self)
By default, prints the string representation of self.to_dict()
 
to_dict(self, include_id=False)
Converts the model into a dictionary suitable for passing into MongoDB.
 
save(self)
Saves the model in MongoDB.
 
delete(self)
Removes the model's entry from the database if it exists
 
__setattr__(self, name, value)
x.__setattr__('name', value) <==> x.name = value
 
__getattribute__(self, name)
x.__getattribute__('name') <==> x.name

Inherited from object: __delattr__, __format__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
collection(cls)
A class method that returns the MongoDB collection that instances of the class will be stored in.
 
find_by_id(cls, oid)
Finds an instance of a document by its unique id.
 
find_one(cls, query={})
Finds the first instance of cls matching query in the database and returns it.
 
find(cls, query=None, sort=None, limit=0)
Finds instances of cls in the database.
 
ensure_index(cls, key_or_list)
Calls ensure_index on the MongoDB collection associated with this class.
Class Variables [hide private]
  _id = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

 

By default, stores everything from kwargs into self as an attribute with the same name

Overrides: object.__init__

collection(cls)
Class Method

 

A class method that returns the MongoDB collection that instances of the class will be stored in. By default, the collection name is the lowercased classname

__str__(self)
(Informal representation operator)

 

By default, prints the string representation of self.to_dict()

Overrides: object.__str__

to_dict(self, include_id=False)

 

Converts the model into a dictionary suitable for passing into MongoDB. By default, it dumps all attributes not prefixed with '_' into the dictionary.

save(self)

 

Saves the model in MongoDB. By default, it simply writes the results of to_dict() into the database. If the field self._id is None, it performs and insert and sets self._id to the id of the newly inserted entry. If self._id is already set, it updates the existing field

find_by_id(cls, oid)
Class Method

 

Finds an instance of a document by its unique id. oid can either be an ObjectId or its string representation

find_one(cls, query={})
Class Method

 

Finds the first instance of cls matching query in the database and returns it. Information about the query argument can be found in the PyMongo documentation for the Collection class.

find(cls, query=None, sort=None, limit=0)
Class Method

 

Finds instances of cls in the database. Information about query, sort, and limit can be found in the PyMongo documentation for the Collection class.

ensure_index(cls, key_or_list)
Class Method

 

Calls ensure_index on the MongoDB collection associated with this class. Read the PyMongo documentation for more information.

__setattr__(self, name, value)

 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

__getattribute__(self, name)

 

x.__getattribute__('name') <==> x.name

Overrides: object.__getattribute__
(inherited documentation)