summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2015-05-31 10:47:28 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2015-05-31 10:47:28 +0100
commit0b5270eab393fad20faa7a6a9720af18c97b1773 (patch)
treede32d3300256be1bfc8626361970efa32b133ce5 /factory
parente9851a7d51afffea2a5679934ad6284c0835cfa2 (diff)
downloadfactory-boy-0b5270eab393fad20faa7a6a9720af18c97b1773.tar
factory-boy-0b5270eab393fad20faa7a6a9720af18c97b1773.tar.gz
Properly handle custom Django managers (Closes #201).
The actual behavior of Django with custom managers and inherited abstract models is rather complex, so this had to be adapted to the actual Django source code.
Diffstat (limited to 'factory')
-rw-r--r--factory/django.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/factory/django.py b/factory/django.py
index 74e4fdb..e4a3ea7 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -115,7 +115,14 @@ class DjangoModelFactory(base.Factory):
if model_class is None:
raise base.AssociatedClassError("No model set on %s.%s.Meta"
% (cls.__module__, cls.__name__))
- manager = model_class.objects
+
+ try:
+ manager = model_class.objects
+ except AttributeError:
+ # When inheriting from an abstract model with a custom
+ # manager, the class has no 'objects' field.
+ manager = model_class._default_manager
+
if cls._meta.database != DEFAULT_DB_ALIAS:
manager = manager.using(cls._meta.database)
return manager