class GeoModel(Document): geo_point_field = fields.PointField() geo_line_field = fields.LineStringField() geo_polygon_field = fields.PolygonField() geo_multi_point_field = fields.MultiPointField() geo_multi_line_field = fields.MultiLineStringField() geo_multi_poly_field = fields.MultiPolygonField()
class GeoDoc(Document): geo_point_field = fields.GeoPointField() point_field = fields.PointField() line_field = fields.LineStringField() poly_field = fields.PolygonField() multi_point_field = fields.MultiPointField() multi_line_field = fields.MultiLineStringField() multi_poly_field = fields.MultiPolygonField()
class Person(Document): _id = fields.StringField() index = fields.IntField(unique=True) guid = fields.UUIDField(unique=True) has_died = fields.BooleanField() balance = fields.FloatField() picture = fields.URLField() age = fields.IntField() eyeColor = fields.StringField() name = fields.StringField() gender = fields.StringField() company_id = fields.IntField() email = fields.EmailField(unique=True) phone = fields.StringField() address = fields.MultiLineStringField() about = fields.MultiLineStringField() registered = fields.DateTimeField() tags = fields.ListField(fields.StringField()) friends = fields.ListField(fields.DictField()) greeting = fields.MultiLineStringField() favouriteFood = fields.ListField(fields.StringField()) # this field will require splitting into fruit and vegetables favouriteFruits = fields.ListField(fields.StringField()) favouriteVegetables = fields.ListField(fields.StringField()) KNOWN_FRUITS = ['apple', 'orange', 'banana', 'strawberry', 'cucumber'] KNOWN_VEGGIES = ['beetroot', 'carrot', 'celery'] @staticmethod def split_foods_into_fruits_and_vegetables(foods): """ Take a list of foods and split into a list of fruits and a list of veggies. :param foods: list of foods :return: tuple containing list of ruits first, then veggies """ fruits = [f for f in foods if f in Person.KNOWN_FRUITS] veggies = [f for f in foods if f in Person.KNOWN_VEGGIES] return (fruits, veggies)
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()