summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-05-03 01:15:21 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-05-03 01:15:21 +0200
commit2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d (patch)
tree4ffd3f7b25661e0fb36fc0fc41fb58def584f8c3 /docs
parent56a5db608f457259f7e69a5e01225adaf7016a31 (diff)
downloadfactory-boy-2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d.tar
factory-boy-2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d.tar.gz
Add LazyStub.factory_parent (See #55).
Diffstat (limited to 'docs')
-rw-r--r--docs/changelog.rst3
-rw-r--r--docs/reference.rst18
2 files changed, 21 insertions, 0 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst
index da22b13..0baa3f7 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -8,6 +8,9 @@ ChangeLog
- Add :class:`~factory.fuzzy.FuzzyDate` thanks to `saulshanabrook <https://github.com/saulshanabrook>`_
- Add :class:`~factory.fuzzy.FuzzyDateTime` and :class:`~factory.fuzzy.FuzzyNaiveDateTime`.
+ - Add a :attr:`~factory.containers.LazyStub.factory_parent` attribute to the
+ :class:`~factory.containers.LazyStub` passed to :class:`~factory.LazyAttribute`, in order to access
+ fields defined in wrapping factories.
*Deprecation:*
diff --git a/docs/reference.rst b/docs/reference.rst
index 09d9ceb..ad921fa 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -353,6 +353,11 @@ accept the object being built as sole argument, and return a value.
'leo@example.com'
+The object passed to :class:`LazyAttribute` is not an instance of the target class,
+but instead a :class:`~containers.LazyStub`: a temporary container that computes
+the value of all declared fields.
+
+
Decorator
~~~~~~~~~
@@ -798,6 +803,19 @@ Obviously, this "follow parents" hability also handles overriding some attribute
'cn'
+This feature is also available to :class:`LazyAttribute` and :class:`LazyAttributeSequence`,
+through the :attr:`~containers.LazyStub.factory_parent` attribute of the passed-in object:
+
+.. code-block:: python
+
+ class CompanyFactory(factory.Factory):
+ FACTORY_FOR = Company
+ country = factory.SubFactory(CountryFactory)
+ owner = factory.SubFactory(UserFactory,
+ language=factory.LazyAttribute(lambda user: user.factory_parent.country.language),
+ )
+
+
Iterator
""""""""