aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRobrecht De Rouck <Robrecht.De.Rouck@gmail.com>2013-12-25 01:46:22 +0100
committerRaphaƫl Barrois <raphael.barrois@polytechnique.org>2013-12-30 14:14:08 +0100
commitc404da5080c92527e26c6b82d5cc5d7d88ba3d9a (patch)
tree8b9278b4d74ff705c26361187bdc494f57d0e2e4 /docs
parent874b5361d2972dd6feb2d26b74e37eba2434ba04 (diff)
downloadfactory-boy-c404da5080c92527e26c6b82d5cc5d7d88ba3d9a.tar
factory-boy-c404da5080c92527e26c6b82d5cc5d7d88ba3d9a.tar.gz
Document custom manager method recipe (Closes #119).
Diffstat (limited to 'docs')
-rw-r--r--docs/recipes.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/recipes.rst b/docs/recipes.rst
index c1f3700..9e07413 100644
--- a/docs/recipes.rst
+++ b/docs/recipes.rst
@@ -291,3 +291,25 @@ Here, we want:
name = "ACME, Inc."
country = factory.SubFactory(CountryFactory)
owner = factory.SubFactory(UserFactory, country=factory.SelfAttribute('..country'))
+
+
+Custom manager methods
+----------------------
+
+Sometimes you need a factory to call a specific manager method other then the
+default :meth:`Model.objects.create() <django.db.models.query.QuerySet.create>` method:
+
+.. code-block:: python
+
+ class UserFactory(factory.DjangoModelFactory):
+ FACTORY_FOR = UserenaSignup
+ username = "l7d8s"
+ email = "my_name@example.com"
+ password = "my_password"
+
+ @classmethod
+ def _create(cls, target_class, *args, **kwargs):
+ """Override the default ``_create`` with our custom call."""
+ manager = cls._get_manager(target_class)
+ # The default would use ``manager.create(*args, **kwargs)``
+ return manager.create_user(*args, **kwargs)