class User(Document): """ :ivar str username: :ivar uuid googleSessionId """ username = fields.StringField(required=True, null=False) googleSessionId = fields.UUIDField(required=True, null=False)
class Route(Document, metaclass=MetaBaseTemplate): author = fields.UUIDField(required=True) title = fields.StringField(validate=validate.Length(max=255), required=True) vectors = fields.ListField(fields.EmbeddedField(Vector), missing=list) is_public = fields.BooleanField(missing=False, default=False) created = fields.DateTimeField(missing=datetime.utcnow) class Meta: collection_name = "routes"
class MySchema(Schema): string = fields.StringField() uuid = fields.UUIDField() number = fields.NumberField() integer = fields.IntegerField() decimal = fields.DecimalField() boolean = fields.BooleanField() float = fields.FloatField() url = fields.UrlField() email = fields.EmailField() constant = fields.ConstantField("const")
class MySchema(EmbeddedSchema): string = fields.StringField() uuid = fields.UUIDField() number = fields.NumberField() integer = fields.IntegerField() decimal = fields.DecimalField() boolean = fields.BooleanField() formattedstring = fields.FormattedStringField('Hello {to_format}') float = fields.FloatField() # localdatetime = fields.LocalDateTimeField() url = fields.UrlField() email = fields.EmailField() constant = fields.ConstantField("const")
class Blog(Document, metaclass=MetaBaseTemplate): __collection__ = 'blog' title = fields.StringField(validate=validate.Length(max=128), required=True) text = fields.StringField(validate=validate.Length(min=128), required=True) user = fields.UUIDField(required=True) created = fields.DateTimeField(missing=datetime.datetime.now) comments = fields.ListField(fields.EmbeddedField(Comment), missing=list) areal = fields.EmbeddedField(Areal, missing=dict) class Meta: pass
class ImageDocument(Document, metaclass=MetaBaseTemplate): public_id = fields.StringField(required=True) filename = fields.StringField() tags = fields.ListField(fields.StringField, missing=list) url = fields.UrlField(required=True) signature = fields.StringField() etag = fields.StringField() user = fields.UUIDField(required=True) liked = fields.IntegerField(missing=0) created_at = fields.DateTimeField(missing=datetime.utcnow) class Meta: collection_name = "images"
class Users(Document, metaclass=MetaBaseTemplate): __collection__ = "users" email = fields.EmailField(required=True, unique=True) guid = fields.UUIDField(missing=uuid.uuid4) name = fields.StringField(validate=validate.Length(max=50), required=True) picture = fields.UrlField() password = fields.StringField(load_only=True) class Meta: pass # indexes = ("email",) @classmethod def create_password(cls, passwd): m = hashlib.sha256() m.update(passwd) return m.hexdigest()
class Comment(EmbeddedDocument, metaclass=MetaBaseTemplate): user = fields.UUIDField(required=True) text = fields.StringField(validate=validate.Length(min=3), required=True) created = fields.DateTimeField(missing=datetime.datetime.utcnow)
class IncorrectTempl(Document): birthday = fields.UUIDField(required=True)