Package couchdbkit :: Package schema :: Module properties_proxy :: Class SchemaProperty
[hide private]
[frames] | no frames]

Class SchemaProperty

source code

         object --+    
                  |    
properties.Property --+
                      |
                     SchemaProperty

Schema property. It allows you add a DocumentSchema instance 
 a member of a Document object. It returns a
`schemaDocumentSchema` object.

 Exemple :
 
         >>> from couchdbkit import *
         >>> class Blog(DocumentSchema):
         ...     title = StringProperty()
         ...     author = StringProperty(default="me")
         ... 
         >>> class Entry(Document):
         ...     title = StringProperty()
         ...     body = StringProperty()
         ...     blog = SchemaProperty(Blog())
         ... 
         >>> test = Entry()
         >>> test._doc
         {'body': None, 'doc_type': 'Entry', 'title': None, 'blog': {'doc_type': 'Blog', 'author': u'me', 'title': None}}
         >>> test.blog.title = "Mon Blog"
         >>> test._doc
         {'body': None, 'doc_type': 'Entry', 'title': None, 'blog': {'doc_type': 'Blog', 'author': u'me', 'title': u'Mon Blog'}}
         >>> test.blog.title
         u'Mon Blog'
         >>> from couchdbkit import Server
         >>> s = Server()
         >>> db = s.create_db('couchdbkit_test')
         >>> Entry._db = db 
         >>> test.save()
         >>> doc = Entry.objects.get(test.id)
         >>> doc.blog.title
         u'Mon Blog'
         >>> del s['simplecouchdb_test']

 

Instance Methods [hide private]
 
__init__(self, schema, verbose_name=None, name=None, required=False, validators=None, default=None)
Default constructor for a property.
source code
 
default_value(self)
return default value
source code
 
empty(self, value)
test if value is empty
source code
 
validate(self, value, required=True)
validate value
source code
 
to_python(self, value)
convert to python type
source code
 
to_json(self, value)
convert to json, Converted value is saved in couchdb.
source code

Inherited from properties.Property: __delete__, __get__, __property_config__, __property_init__, __set__

Inherited from properties.Property (private): _to_json, _to_python

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

Class Variables [hide private]

Inherited from properties.Property: creation_counter, data_type

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, schema, verbose_name=None, name=None, required=False, validators=None, default=None)
(Constructor)

source code 
Default constructor for a property.

:param verbose_name: str, verbose name of field, could
        be use for description
:param name: str, name of field
:param default: default value
:param required: True if field is required, default is False
:param validators: list of callable or callable, field validators
function that are executed when document is saved.

Overrides: object.__init__
(inherited documentation)

default_value(self)

source code 

return default value

Overrides: properties.Property.default_value
(inherited documentation)

empty(self, value)

source code 

test if value is empty

Overrides: properties.Property.empty
(inherited documentation)

validate(self, value, required=True)

source code 

validate value

Overrides: properties.Property.validate
(inherited documentation)

to_python(self, value)

source code 

convert to python type

Overrides: properties.Property.to_python
(inherited documentation)

to_json(self, value)

source code 

convert to json, Converted value is saved in couchdb.

Overrides: properties.Property.to_json
(inherited documentation)