diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-05-31 10:57:53 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-05-31 10:57:53 +0100 |
commit | 9246fa6d26ca655c02ae37bbfc389d9f34dfba16 (patch) | |
tree | 4cfb1c34c94b83783ef9c5c27c56b9e178779df2 /docs/orms.rst | |
parent | 0b5270eab393fad20faa7a6a9720af18c97b1773 (diff) | |
download | factory-boy-9246fa6d26ca655c02ae37bbfc389d9f34dfba16.tar factory-boy-9246fa6d26ca655c02ae37bbfc389d9f34dfba16.tar.gz |
Improve ORM layer import paths (Closes #186).
You may now use the following code:
import factory
factory.alchemy.SQLAlchemyModelFactory
factory.django.DjangoModelFactory
factory.mongoengine.MongoEngineFactory
Diffstat (limited to 'docs/orms.rst')
-rw-r--r-- | docs/orms.rst | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/docs/orms.rst b/docs/orms.rst index bbe91e6..26390b5 100644 --- a/docs/orms.rst +++ b/docs/orms.rst @@ -273,6 +273,34 @@ factory_boy supports `MongoEngine`_-style models, through the :class:`MongoEngin This feature makes it possible to use :class:`~factory.SubFactory` to create embedded document. +A minimalist example: + +.. code-block:: python + + import mongoengine + + class Address(mongoengine.EmbeddedDocument): + street = mongoengine.StringField() + + class Person(mongoengine.Document): + name = mongoengine.StringField() + address = mongoengine.EmbeddedDocumentField(Address) + + import factory + + class AddressFactory(factory.mongoengine.MongoEngineFactory): + class Meta: + model = Address + + street = factory.Sequence(lambda n: 'street%d' % n) + + class PersonFactory(factory.mongoengine.MongoEngineFactory): + class Meta: + model = Person + + name = factory.Sequence(lambda n: 'name%d' % n) + address = factory.SubFactory(AddressFactory) + SQLAlchemy ---------- @@ -327,8 +355,9 @@ A (very) simple example: Base.metadata.create_all(engine) + import factory - class UserFactory(SQLAlchemyModelFactory): + class UserFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: model = User sqlalchemy_session = session # the SQLAlchemy session object |