예제 #1
0
class ParentWithRelationship(motorengine.Document):

    meta = {"collection": "test_parent_reference"}
    before_child = motorengine.ListField(
        motorengine.ReferenceField("ChildRegisteredBefore"))
    after_child = motorengine.ListField(
        motorengine.ReferenceField("ChildRegisteredAfter"))
    name = motorengine.StringField()
예제 #2
0
class Player(motorengine.Document):

    meta = {"collection": "test_player"}
    first_name = motorengine.StringField(required=True)
    last_name = motorengine.StringField(required=True)
    opponent = motorengine.ReferenceField("Player")
    players = motorengine.ListField(motorengine.ReferenceField("Player"))
    articles = motorengine.ListField(motorengine.ReferenceField("Article"))
    embedded_list_articles = motorengine.EmbeddedDocumentListField(
        EmbeddedArticle)
예제 #3
0
class ProfessorMetadata(motorengine.EmbeddedDocument):

    meta = {"collection": "test_professor_metadata"}
    id = motorengine.StringField(primary_key=False)
    first_name = motorengine.StringField()
    last_name = motorengine.StringField()
    departments = motorengine.ListField(motorengine.StringField())
예제 #4
0
class Reporter(motorengine.Document):

    meta = {"collection": "test_reporter"}
    id = motorengine.StringField(primary_key=True)
    first_name = motorengine.StringField(required=True)
    last_name = motorengine.StringField(required=True)
    email = motorengine.EmailField()
    awards = motorengine.ListField(motorengine.StringField())
    articles = motorengine.ListField(motorengine.ReferenceField(Article))
    embedded_articles = motorengine.ListField(
        motorengine.EmbeddedDocumentField(EmbeddedArticle))
    embedded_list_articles = motorengine.EmbeddedDocumentListField(
        EmbeddedArticle)
    generic_reference = motorengine.GenericReferenceField(
        choices=[Article, Editor])
    generic_embedded_document = motorengine.GenericEmbeddedDocumentField(
        choices=[EmbeddedArticle, EmbeddedFoo])
    generic_references = motorengine.ListField(
        motorengine.GenericReferenceField(choices=[Article, Editor]))
예제 #5
0
class Portfolio(motorengine.Document):
    user = motorengine.StringField(max_length=128, required=True)
    cash = motorengine.IntField(default=1000000)
    positions = motorengine.ListField(
        motorengine.EmbeddedDocumentField(Position))

    async def make_deal(self, sym, units, price):
        if units == 0:
            raise Exception('Amount must be positive!')

        amount = units * price
        if amount > self.cash:
            raise Exception('Cash limit exceeded!')

        pnl = 0
        for position in self.positions:
            if position.symbol == sym:
                pnl = position.update(units, price)
                if position.units == 0:
                    self.positions.remove(position)
                break
        else:
            if units < 0:
                raise Exception('Position limit exceeded!')
            else:
                self.positions.append(
                    Position(symbol=sym, units=units, price=price))

        self.cash -= amount
        # self.cash += pnl
        await self.save()

    async def reset(self):
        self.cash = 1000000
        self.positions = []
        await self.save()

    def serialize(self):
        return {
            # 'user': self.user,
            'cash': self.cash,
            'positions': [p.serialize() for p in self.positions],
        }
예제 #6
0
class Other(motorengine.Document):
    __collection__ = "Other_%s" % COLLECTION
    items = motorengine.ListField(
        motorengine.EmbeddedDocumentField(MotorDocument))
예제 #7
0
class Bar(motorengine.EmbeddedDocument):
    some_list_field = motorengine.ListField(motorengine.StringField(),
                                            required=True)
예제 #8
0
class ErroneousModel(motorengine.Document):
    meta = {"collection": "test_colliding_objects_model"}

    objects = motorengine.ListField(motorengine.StringField())
예제 #9
0
class ProfessorVector(motorengine.Document):

    meta = {"collection": "test_professor_vector"}
    vec = motorengine.ListField(motorengine.FloatField())
    metadata = motorengine.EmbeddedDocumentField(ProfessorMetadata)
예제 #10
0
class User(motorengine.Document):

    name = motorengine.StringField()
    email = motorengine.EmailField()
    posts = motorengine.ListField(motorengine.ReferenceField("__main__.Post"))