From 2c8d2cd5c9bf3074bd70559a850d77bd3a28ae8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 3 May 2013 01:15:21 +0200 Subject: Add LazyStub.factory_parent (See #55). --- docs/reference.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/reference.rst') 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 """""""" -- cgit v1.2.3