diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 01:30:15 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-08-28 01:30:15 +0200 |
commit | 297a111cc918c6451f1b66e3fe3572a9f3fc6b8f (patch) | |
tree | 1b7d68414a71b8e072b285d1a142da2ad3fc75af /factory/base.py | |
parent | 7fc3e4cbdae050dcde49ea3101636ddf57d6c96d (diff) | |
download | factory-boy-297a111cc918c6451f1b66e3fe3572a9f3fc6b8f.tar factory-boy-297a111cc918c6451f1b66e3fe3572a9f3fc6b8f.tar.gz |
Allow FACTORY_FOR = 'app.Model' for Django (Closes #66).
Diffstat (limited to 'factory/base.py')
-rw-r--r-- | factory/base.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/factory/base.py b/factory/base.py index ac906de..1b9fa0d 100644 --- a/factory/base.py +++ b/factory/base.py @@ -331,6 +331,15 @@ class BaseFactory(object): return kwargs @classmethod + def _load_target_class(cls): + """Extension point for loading target classes. + + This can be overridden in framework-specific subclasses to hook into + existing model repositories, for instance. + """ + return getattr(cls, CLASS_ATTRIBUTE_ASSOCIATED_CLASS) + + @classmethod def _prepare(cls, create, **kwargs): """Prepare an object for this factory. @@ -338,7 +347,7 @@ class BaseFactory(object): create: bool, whether to create or to build the object **kwargs: arguments to pass to the creation function """ - target_class = getattr(cls, CLASS_ATTRIBUTE_ASSOCIATED_CLASS) + target_class = cls._load_target_class() kwargs = cls._adjust_kwargs(**kwargs) # Remove 'hidden' arguments. |