warehouses.models¶
Graph of models in the warehouses app and related apps.
This module defines models and model managers for storing and retrieving data.
These models provide a layer of abstraction between Cyphon and the storage engines with which it interacts.
| Class | Description |
|---|---|
Collection |
A document collection, doctype, or database table. |
CollectionManager |
Model manager for Collections. |
Warehouse |
A database or search index. |
WarehouseManager |
Model manager for Warehouses. |
-
class
warehouses.models.Collection(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelDefine a document collection, document type, or database table.
-
warehouse¶ Warehouse – The
Warehousein which theCollectionresides.
-
name¶ str – The name of a document collection, doc type, or database table, depending on the
Warehousebackend.
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
company¶ The
Companyassociated with the Collection.Returns: The Companyassociated with the Collection’sDistillery.Return type: Company
-
distillery¶ Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
place.restaurantis aReverseOneToOneDescriptorinstance.
-
engine¶ An
Enginefor handling documents.Returns: An instance of an Enginesubclass that can be used to handle documents associated with the Collection.Return type: Engine
-
filter_ids(doc_ids, fields, value)[source]¶ Find the ids of documents that match a value.
Parameters: Returns: The subset of ids for documents containing the given value in one or more of the specified fields.
Return type:
-
find(query, sorter=None, page=1, page_size=10)[source]¶ Find documents matching a query.
Parameters: - query (
EngineQuery) – AnEngineQuerydefining critieria for matching documents in the index or time series. - sorter (
SorterorNone) – ASorterdefining how results should be ordered. - page (int) – The page of results to return.
- page_size (int) – The number of documents per page of results.
Returns: A dictionary with keys ‘count’ and ‘results’. The ‘count’ value is the total number of documents matching the search criteria. The ‘results’ value is a list of documents from the search result, with the doc ids added to each document.
Return type: - query (
-
find_by_id(doc_ids)[source]¶ Find one or more documents by id.
Parameters: doc_ids ( strorlistofstr) – A document id or a list of document ids.Returns: Documents that match the given id(s). Returns a listof documents if doc_ids is alist; otherwise returns a single document. If no matches are found, returnsNone.Return type: dict,listofdict, orNone
-
get_backend()[source]¶ Get the backend used by the Collection.
Returns the name of the backend associated with the Collection’s
Warehouse. This method can be used to display the backend in the admin list view.Returns: The backend used by the Collection’s Warehouse.Return type: str
-
get_company()[source]¶ Get the
Companyassociated with the Collection.This method is used to display the Company in the admin list view.
Returns: The Companyassociated with the Collection’sDistillery.Return type: Company
-
get_sample(doc)[source]¶ Get a teaser for a doc.
Parameters: doc (dict) – A document that conforms to the Collection’s schema, which is defined by the Containerused by the Collection’sDistillery.Returns: A teaser for the original the doc. Return type: dict
-
get_schema()[source]¶ Get the
DataFieldsused by documents in the Collection.Returns: The DataFieldsin theContainerused by the Collection’sDistillery.Return type: listofDataFields
-
get_warehouse_name()[source]¶ Get the name of the Collection’s
Warehouse.This method is used to display the Warehouse name in the admin list view.
Returns: The name of the Collection’s Warehouse.Return type: str
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
in_time_series()[source]¶ Whether the Collection’s
Warehouseis a time series.Returns a
boolindicating whether the Collection’sWarehousestores data in a time series (e.g., timestamped indexes).Returns: Whether data is stored as a time series. Return type: bool
-
insert(doc)[source]¶ Save a document to the Collection.
Parameters: doc (dict) – A document to insert into the data store represented by the Collection. Returns: The id of the inserted document. Return type: str
-
name A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <warehouses.models.CollectionManager object>¶
-
remove_by_id(doc_ids)[source]¶ Remove the documents with the given ids.
Parameters: doc_ids ( strorlistofstr) – An id or list of ids of documents to remove from the Collection.Returns: Return type: None
-
warehouse Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
child.parentis aForwardManyToOneDescriptorinstance.
-
warehouse_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
warehouses.models.CollectionManager[source]¶ Bases:
django.db.models.manager.ManagerManage
Collectionobjects.Customizes the default Django model manager by adding and overriding methods.
-
get_by_natural_key(backend, database, name)[source]¶ Get a
Collectionby its natural key.Allows retrieval of a
Collectionby its natural key instead of its primary key.Parameters: - backend (str) – The backend of the
Warehouseto which theCollectionbelongs. - database (str) – The name of the
Warehouseto which theCollectionbelongs. - name (str) – The name of the
Collection.
Returns: The
Collectionassociated with the natural key.Return type: - backend (str) – The backend of the
-
get_queryset()[source]¶ Get the initial
Collectionqueryset.Overrides the default get_queryset method to also select related
Warehouses.Returns: A QuerySetofCollections.Return type: QuerySetSee also
Django’s documentation contains instructions on how to select related objects and modify an initial queryset.
-
-
class
warehouses.models.Warehouse(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelDefine a database or search index.
-
backend¶ str – Lowercase name of a storage engine, such as ‘elasticsearch’. This corresponds to the base file name of the module containing the
Enginesubclass for that storage engine. Choices are constrained toBACKEND_CHOICES.
-
name¶ str – The name of a database or search index.
-
time_series¶ bool – Whether data should be stored as a time series (e.g., timestamped indexes).
-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
backend A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
clean()[source]¶ Validate the model as a whole.
Provides custom model validation. If time_series is
True, checks that the backend can work with a time series.Returns: Return type: None Raises: ValidationError– If time_series isTruebut the selected backend cannot work with a time series, or if any default Django model validations fail.See also
See Django’s documentation for the
clean()method.
-
collections¶ Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
get_backend_display(**morekwargs)¶
-
get_module()[source]¶ Get the module for interacting with the backend.
Returns: The module that contains the Enginesubclass for interacting with the Warehouse’s backend.Return type: module
-
id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
name A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
objects= <warehouses.models.WarehouseManager object>¶
-
time_series A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
-
class
warehouses.models.WarehouseManager[source]¶ Bases:
django.db.models.manager.ManagerManage
Warehouseobjects.Adds methods to the default Django model manager.