API Docs: OGitM¶
- class ogitm.Model(*args, **kwargs)[source]¶
Base class for models
Subclass this class to declare a model. Model provides a default initialiser, an equivalence function, and the save() and find() methods.
Parameters: - model_id (int) – If this is provided, the model will be initialised with the attributes specified by the document with that id in the database. This is generally for internal use (i.e, creating the object after a search has been completed) but it may be useful.
- kwargs (mixed) – This is the more usual way of initialising the model - that is, by passing in key=val pairs describing the values passed to the fields specified by the model. The default initialiser will then go through all of the arguments, check that they are known fields, and assign them.
Attribute id: The instance will always have this attribute referring to the id that it refers to in the database. It will be None if the instance has not been inserted into the database (this should never happen, though!)
- classmethod find(**kwargs)[source]¶
Finds documents in the database.
Given keyword arguments (which have the same format as the arguments given to gitdb.GitDB.find()), this method returns a ReturnSet containing all of the matching documents.
Parameters: kwargs (mixed) – See gitdb.GitDB.find() for the full finding syntax. Returns: ReturnSet of all of the matching documents.
- class ogitm.ReturnSet(ids, cls)[source]¶
A class representing the documents returned by a particular query.
This class can be used to further narrow down the search (find()), or return initialised instances of the model that found them (first(), all(), __getitem__()). It can also tell you how many items the set currently contains (__len__())
The documents are returned sorted in order of the ids. This ensures that further operations on a set will preserve order, but should not be relied on, as the specifics of document ids is not part of the public interface.
- find(**kwargs)[source]¶
Refine the terms of the original search
Using the model that created this set, find which documents match the new queres, then update this set to point to the intersection of both the old and new queries.
Parameters: kwargs (mixed) – See Model.find(). Returns: This set, to allow for chaining method calls.
- class ogitm.MetaModel(name, bases, dct, **kwargs)[source]¶
Metatype for OGitM Models
Generally, a user should subclass Model instead of touching this class. However, it is useful to be aware of the functions that MetaModel can perform. Firstly, upon instantiation it removes all class attributes that extend BaseField, and assigns them to an internal dict. It also ensures that any class that overrides __init__() calls the super method. This makes sure that the Model should always be in a useable state.
It also provides the get_attributes() class method which can be used to get the data for any particular class.