Skip to content
Myr

verbage

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonathan Como · committed by Jonathan Como · parent a8498b6 · Browse files · 1 file+3 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−4 removed

  • other:+3 added−4 removed

1 file+3 added−4 removed

modified:docs/patterns/mongokit.rst+3 added-4 removed
52 unmodified lines
53 def max_length(length):54 def validate(value):55 if len(value) <= length:56 return True57 # must have %s in error format string to have mongokit place key in there57 raise ValidationError('%s must be at most {0} characters long'.format(length))58 raise ValidationError('%s must be at most {} characters long'.format(length))59 return validate6061 class User(Document):62 structure = {
13 unmodified lines
767778This example shows you how to define your schema (named structure), a79validator for the maximum character length and uses a special MongoKit feature79called `use_dot_notation`. When you define a ValidationError, you can add the `%s`80into the format string to have the value placed in there for the final error message.81ValueErrors can also be thrown as an alternative. Per default MongoKit behaves like a python80called `use_dot_notation`. Per default MongoKit behaves like a python81dictionary but with `use_dot_notation` set to ``True`` you can use your82documents like you use models in nearly any other ORM by using dots to83separate between attributes.84
59 unmodified lines