summaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-13 16:06:13 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-05-13 16:06:13 +0200
commit64a059101d0119e18c1cb0b15b0e9e15795ccba1 (patch)
tree7f15e7e83dbc6fe9095aac937c211f7b5c1fbaad /README.rst
parentf57a0c213ffe12325e20e69e5cc03ff27633d06c (diff)
downloadfactory-boy-64a059101d0119e18c1cb0b15b0e9e15795ccba1.tar
factory-boy-64a059101d0119e18c1cb0b15b0e9e15795ccba1.tar.gz
Improve handling of custom build/create functions.
Only public attributes (i.e not starting with _) will be handled properly. Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'README.rst')
-rw-r--r--README.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index cb73a17..e141b93 100644
--- a/README.rst
+++ b/README.rst
@@ -165,3 +165,21 @@ Sequences can be combined with lazy attributes::
email = factory.LazyAttributeSequence(lambda a, n: '{0}+{1}@example.com'.format(a.name, n).lower())
UserFactory().email # => mark+0@example.com
+
+Customizing creation
+--------------------
+
+Sometimes, the default build/create by keyword arguments doesn't allow for enough
+customization of the generated objects. In such cases, you should override the
+:meth:`base.Factory._prepare` method::
+
+ class UserFactory(factory.Factory):
+ @classmethod
+ def _prepare(cls, create, **kwargs):
+ password = kwargs.pop('password', None)
+ user = super(UserFactory, cls)._prepare(create, kwargs)
+ if password:
+ user.set_password(user)
+ if create:
+ user.save()
+ return user