summaryrefslogtreecommitdiff
path: root/docs/introduction.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/introduction.rst')
-rw-r--r--docs/introduction.rst22
1 files changed, 17 insertions, 5 deletions
diff --git a/docs/introduction.rst b/docs/introduction.rst
index 8bbb10c..86e2046 100644
--- a/docs/introduction.rst
+++ b/docs/introduction.rst
@@ -99,7 +99,7 @@ This is achieved with the :class:`~factory.Sequence` declaration:
>>> UserFactory()
<User: user2>
-.. note:: For more complex situations, you may also use the :meth:`~factory.@sequence` decorator:
+.. note:: For more complex situations, you may also use the :meth:`~factory.@sequence` decorator (note that ``self`` is not added as first parameter):
.. code-block:: python
@@ -107,7 +107,7 @@ This is achieved with the :class:`~factory.Sequence` declaration:
FACTORY_FOR = models.User
@factory.sequence
- def username(self, n):
+ def username(n):
return 'user%d' % n
@@ -140,7 +140,19 @@ taking the object being built and returning the value for the field:
<User: user3 (doe@example.com)>
-.. note:: As for :class:`~factory.Sequence`, a :meth:`~factory.@lazy_attribute` decorator is available.
+.. note:: As for :class:`~factory.Sequence`, a :meth:`~factory.@lazy_attribute` decorator is available:
+
+
+.. code-block:: python
+
+ class UserFactory(factory.Factory):
+ FACTORY_FOR = models.User
+
+ username = factory.Sequence(lambda n: 'user%d' % n)
+
+ @factory.lazy_attribute
+ def email(self):
+ return '%s@example.com' % self.username
Inheritance
@@ -227,7 +239,7 @@ All factories support two built-in strategies:
as for a Django model.
Starting from 2.0, :meth:`factory.Factory.create` simply calls ``AssociatedClass(**kwargs)``.
- You should use :class:`~factory.DjangoModelFactory` for Django models.
+ You should use :class:`~factory.django.DjangoModelFactory` for Django models.
When a :class:`~factory.Factory` includes related fields (:class:`~factory.SubFactory`, :class:`~factory.RelatedFactory`),
@@ -253,6 +265,6 @@ Calling a :class:`~factory.Factory` subclass will provide an object through the
<MyClass: X (saved)>
-The default strategy can ba changed by setting the class-level :attr:`~factory.Factory.FACTROY_STRATEGY` attribute.
+The default strategy can be changed by setting the class-level :attr:`~factory.Factory.FACTORY_STRATEGY` attribute.