summaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 14:46:03 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2014-05-18 14:46:03 +0200
commitb245a83019a8735d0c80c07275cd426bc60dd9f8 (patch)
tree00c936e2479056d829f3d6377a68f3e5cbb6af50 /README.rst
parentfd3d2583580fc18ff1531b5be02238c8c2addccc (diff)
downloadfactory-boy-b245a83019a8735d0c80c07275cd426bc60dd9f8.tar
factory-boy-b245a83019a8735d0c80c07275cd426bc60dd9f8.tar.gz
Update docs for class Meta.
Diffstat (limited to 'README.rst')
-rw-r--r--README.rst21
1 files changed, 15 insertions, 6 deletions
diff --git a/README.rst b/README.rst
index b35adc5..787d754 100644
--- a/README.rst
+++ b/README.rst
@@ -94,7 +94,8 @@ Usage
Defining factories
""""""""""""""""""
-Factories declare a set of attributes used to instantiate an object. The class of the object must be defined in the FACTORY_FOR attribute:
+Factories declare a set of attributes used to instantiate an object.
+The class of the object must be defined in the ``target`` field of a ``class Meta:`` attribute:
.. code-block:: python
@@ -102,7 +103,8 @@ Factories declare a set of attributes used to instantiate an object. The class o
from . import models
class UserFactory(factory.Factory):
- FACTORY_FOR = models.User
+ class Meta:
+ target = models.User
first_name = 'John'
last_name = 'Doe'
@@ -110,7 +112,8 @@ Factories declare a set of attributes used to instantiate an object. The class o
# Another, different, factory for the same object
class AdminFactory(factory.Factory):
- FACTORY_FOR = models.User
+ class Meta:
+ target = models.User
first_name = 'Admin'
last_name = 'User'
@@ -164,7 +167,9 @@ These "lazy" attributes can be added as follows:
.. code-block:: python
class UserFactory(factory.Factory):
- FACTORY_FOR = models.User
+ class Meta:
+ target = models.User
+
first_name = 'Joe'
last_name = 'Blow'
email = factory.LazyAttribute(lambda a: '{0}.{1}@example.com'.format(a.first_name, a.last_name).lower())
@@ -183,7 +188,9 @@ Unique values in a specific format (for example, e-mail addresses) can be genera
.. code-block:: python
class UserFactory(factory.Factory):
- FACTORY_FOR = models.User
+ class Meta:
+ target = models.User
+
email = factory.Sequence(lambda n: 'person{0}@example.com'.format(n))
>>> UserFactory().email
@@ -201,7 +208,9 @@ This is handled by the ``SubFactory`` helper:
.. code-block:: python
class PostFactory(factory.Factory):
- FACTORY_FOR = models.Post
+ class Meta:
+ target = models.Post
+
author = factory.SubFactory(UserFactory)