New in version 0.23.
Note
This abstraction is by no means a complete replacement for the normal approach of semantic grouping. Please use it with care. Also note that the API can change. The class can even be removed in future versions of Doqu.
Representation of a document property. Syntax sugar for separate definitions of structure, validators, defaults and labels.
Usage:
class Book(Document):
title = Field(unicode, required=True, default=u'Hi', label='Title')
this is just another way to type:
class Book(Document):
structure = {
'title': unicode
}
validators = {
'title': [validators.Required()]
}
defaults = {
'title': u'Hi'
}
labels = {
'title': u'The Title'
}
Nice, eh? But be careful: the title definition in the first example barely fits its line. Multiple long definitions will turn your document class into an opaque mess of characters, while the semantically grouped definitions stay short and keep related things aligned together. “Semantic sugar” is sometimes pretty bitter, use it with care.
Complex validators still need to be specified by hand in the relevant dictionary. This can be worked around by creating specialized field classes (e.g. EmailField) as it is done e.g. in Django.
Parameters: |
|
---|
Handles externally stored files.
Warning
This field saves the file when process_outgoing() is triggered (see outgoing_processors in DocumentMetadata).
Outdated (replaced) files are not automatically removed.
Usage:
class Doc(Document):
attachment = FileField(base_path=MEDIA_ROOT+'attachments/')
d = Doc()
d.attachment = open('foo.txt')
d.save(db)
dd = Doc.objects(db)[0]
print dd.attachment.file.read()
Parameters: | base_path – A string or callable: the directory where the files should be stored. |
---|
alias of FileWrapper
A FileField that provides extended support for images. The ImageField.file is an ImageWrapper instance.
Usage:
class Photo(Document):
summary = Field(unicode)
image = ImageField(base_path='photos/')
p = Photo(summary='Fido', image=open('fido.jpg'))
p.save(db)
# playing with image
print "The photo is {0}×{1}px".format(*p.image.size)
p.image.rotate(90)
p.image.save()
alias of ImageWrapper