class RegularModel(Document): """ A model class for testing regular flat fields. """ str_field = fields.StringField() str_regex_field = fields.StringField(regex="^valid_regex") url_field = fields.URLField() email_field = fields.EmailField() int_field = fields.IntField() long_field = fields.LongField() float_field = fields.FloatField() boolean_field = fields.BooleanField() nullboolean_field = fields.BooleanField(null=True) date_field = fields.DateTimeField() complexdate_field = fields.ComplexDateTimeField() uuid_field = fields.UUIDField() id_field = fields.ObjectIdField() decimal_field = fields.DecimalField() custom_field = CustomField() # TODO # dynamic_field = fields.DynamicField() # bin_field = fields.BinaryField() # file_field = fields.FileField() # image_field = fields.ImageField() def method(self): return 'method'
class Schema1EmbDoc2(EmbeddedDocument): embdoc2_int = fields.IntField() embdoc2_str = fields.StringField() embdoc2_str_empty = fields.StringField() embdoc2_str_ten = fields.StringField(choices=[str(x) for x in range(11)]) embdoc2_float = fields.FloatField() embdoc2_int_empty = fields.IntField() embdoc2_long = fields.LongField() embdoc2_decimal = fields.DecimalField() embdoc2_complex_datetime = fields.ComplexDateTimeField() embdoc2_list = fields.ListField() embdoc2_ref_doc1 = fields.ReferenceField('Schema1Doc1') embdoc2_emb_embdoc2 = fields.EmbeddedDocumentField('self') embdoc2_emblist_embdoc2 = fields.EmbeddedDocumentListField('self')
class Foo(Document): string = fields.StringField() required = fields.StringField(required=True) choices = fields.StringField(choices=('foo', 'bar', 'baz')) regex = fields.StringField(regex=r'^[a-z]*$') length = fields.StringField(min_length=1, max_length=3) strings = fields.ListField(fields.StringField()) sorted_strings = fields.SortedListField(fields.StringField()) integer = fields.IntField() bounded_int = fields.IntField(min_value=0, max_value=10) longeger = fields.LongField() bounded_long = fields.LongField(min_value=0, max_value=10) floating = fields.FloatField() bounded_float = fields.FloatField(min_value=0.0, max_value=1.0) boolean = fields.BooleanField() datetime = fields.DateTimeField() complex_datetime = fields.ComplexDateTimeField() binary = fields.BinaryField() bounded_binary = fields.BinaryField(max_bytes=8) mapping = fields.MapField(fields.StringField()) uuid = fields.UUIDField() old_geopoint = fields.GeoPointField() point = fields.PointField() line = fields.LineStringField() polygon = fields.PolygonField() points = fields.MultiPointField() lines = fields.MultiLineStringField() polygons = fields.MultiPolygonField() even_length_string = fields.StringField( validation=lambda s: len(s) % 2 == 0) @fields.EmbeddedDocumentField class embedded_bar(EmbeddedDocument): bar = fields.StringField() @fields.EmbeddedDocumentListField class embedded_baz(EmbeddedDocument): baz = fields.StringField()