diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-05-03 01:15:21 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-05-03 01:15:21 +0200 |
commit | 2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d (patch) | |
tree | 4ffd3f7b25661e0fb36fc0fc41fb58def584f8c3 /docs/reference.rst | |
parent | 56a5db608f457259f7e69a5e01225adaf7016a31 (diff) | |
download | factory-boy-2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d.tar factory-boy-2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d.tar.gz |
Add LazyStub.factory_parent (See #55).
Diffstat (limited to 'docs/reference.rst')
-rw-r--r-- | docs/reference.rst | 18 |
1 files changed, 18 insertions, 0 deletions
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 """""""" |