Skip to content

Commit

Permalink
close #450. Document how to use with factory-boy, the factory-boy way.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Jan 27, 2017
1 parent a58490a commit 91e4432
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,19 @@ How to create a Provider
How to use with factory-boy
---------------------------
`factory-boy`_ already ships with integration with ``Faker`. Simply use the
``factory.Faker`` method of ``factory-boy``:
.. code:: python
import factory
from faker import Faker
from myapp.models import Book
fake = Faker()
from myapp.models import User
class Book(factory.Factory):
FACTORY_FOR = Book
class UserFactory(factory.Factory):
class Meta:
model = User
title = factory.LazyAttribute(lambda x: fake.sentence(nb_words=4))
author_name = factory.LazyAttribute(lambda x: fake.name())
name = factory.Faker('name')
Accessing the `random` instance
-------------------------------
Expand Down Expand Up @@ -361,6 +360,7 @@ Credits
.. _community providers: https://faker.readthedocs.io/en/latest/communityproviders.html
.. _LICENSE: https://github.com/joke2k/faker/blob/master/LICENSE.txt
.. _CONTRIBUTING: https://github.com/joke2k/faker/blob/master/CONTRIBUTING.rst
.. _factory-boy: https://github.com/FactoryBoy/factory_boy
.. |pypi| image:: https://img.shields.io/pypi/v/Faker.svg?style=flat-square&label=version
:target: https://pypi.python.org/pypi/Faker
Expand Down
18 changes: 9 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,19 @@ How to create a Provider
How to use with factory-boy
---------------------------
`factory-boy`_ already ships with integration with ``Faker`. Simply use the
``factory.Faker`` method of ``factory-boy``:
.. code:: python
import factory
from faker import Faker
from myapp.models import Book
fake = Faker()
from myapp.models import User
class Book(factory.Factory):
FACTORY_FOR = Book
class UserFactory(factory.Factory):
class Meta:
model = User
title = factory.LazyAttribute(lambda x: fake.sentence(nb_words=4))
author_name = factory.LazyAttribute(lambda x: fake.name())
name = factory.Faker('name')
Accessing the `random` instance
-------------------------------
Expand Down Expand Up @@ -366,6 +365,7 @@ Credits
.. _community providers: https://faker.readthedocs.io/en/latest/communityproviders.html
.. _LICENSE: https://github.com/joke2k/faker/blob/master/LICENSE.txt
.. _CONTRIBUTING: https://github.com/joke2k/faker/blob/master/CONTRIBUTING.rst
.. _factory-boy: https://github.com/FactoryBoy/factory_boy
.. |pypi| image:: https://img.shields.io/pypi/v/Faker.svg?style=flat-square&label=version
:target: https://pypi.python.org/pypi/Faker
Expand Down

0 comments on commit 91e4432

Please sign in to comment.