Created
March 6, 2013 17:23
-
-
Save j2labs/5101136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from schematics.models import Model | |
>>> from schematics.types import StringType, IntType, DateTimeType, BooleanType | |
>>> from schematics.types.compound import ModelType, ListType | |
>>> from schematics.exceptions import ValidationError | |
>>> from schematics.serialize import whitelist | |
>>> class Game(Model): | |
... opponent_id = IntType(required=True) | |
... | |
>>> class Player(Model): | |
... total_games = IntType(min_value=0, required=True) | |
... name = StringType(required=True) | |
... verified = BooleanType() | |
... bio = StringType() | |
... games = ListType(ModelType(Game), required=True) | |
... class Options: | |
... roles = { | |
... 'public': whitelist('total_games', 'name', 'bio', 'games'), | |
... } | |
... | |
>>> p1 = Player(total_games=2, | |
... name='Jms Dnns', | |
... verified=True, | |
... bio='Musician | Hacker', | |
... games=[Game(opponent_id=1), Game(oppenent_id=2)]) | |
>>> | |
>>> p2 = Player(total_games=1, | |
... name='Jokull Solberg', | |
... verified=True, | |
... bio='Creator of @calepinapp @oathapp and @wodboard', | |
... games=[Game(opponent_id=1), Game(oppenent_id=2)]) | |
>>> | |
>>> p1.validate(p1.initial) | |
False | |
>>> | |
>>> p2.errors | |
{'games': {1: [u'Please use a mapping for this field'], 2: [u'Please use a mapping for this field']}} | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment