To create document you should subclass the Document or any subclasses of that.
Djamo implementation of Document. Each document can have any number of key/value pairs as user want, there is no limit. But if user wants to provides some options and details about an specific key he/she should add a keys property to their subclass. keys is a dictionary object. Each key of keys property would be a document key and its value would be another dictionary with some specific key/value. for example:
class students (Document):
fields = {
"name": String(required=True, max_lenght=30),
"age": Integer(min=5, max=40, default=20),
"user": DjanogUser(required=True),
}
Note
Remember that providing a fields attribute is optional
de-serialize each key/value using a serializer.
Get the available value of specfied key in raw_value from serializer_name dictionary
Put value for raw_value to cache_name cache.
Serialize each key/value and return a tuple like: (key, serialized_value)
Validate a value of an specific key against user provided validator of the serializer class and current document validate_<key>
This method is responsible for de-serializing document data from database. If there was a serializer for a key it will call that otherwise simply treat the value like a python data type.
Parameters: |
|
---|
Deserialize a query that stored in item tuple like: (key, value)
This method is responsible for serializing document data to put into database. The important thing to know here is that this method use serializer of each key to serialize and deserialize data. If no serializer sepcified, serialize method will treat data just like common python data types withou serialization.
This method will return a dictionary from serialized data.
Serialize a query that stored in item tuple like: (key, value)
Validate the current document against provided validators of serializer and current document validate_<field> method for each field. The signature of each document level validator for a field should be like:
def validate_<field>(self, value):
# Validation code goes here ....
Remember to replace <field> with your field name.
Meta class for Document object. This class is responsible for creating Document instances.
Note
This class is for Djamo internal usage.