diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-04-14 00:20:33 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2015-04-14 00:20:33 +0200 |
commit | e357919cdb52af96eb67148fd38dced34981821a (patch) | |
tree | 33d6fe6b767d885980a0395418b8a3af5f0c06df /factory | |
parent | 16b414d27d638fd76701f10fe338c67d7d9dfde0 (diff) | |
download | factory-boy-e357919cdb52af96eb67148fd38dced34981821a.tar factory-boy-e357919cdb52af96eb67148fd38dced34981821a.tar.gz |
Remove warnings with Django 1.7 (Closes #195).
Builds upon pull request by @shinuza:
- Properly import ``get_model``
- Run ``django.setup()`` before importing any models.
Diffstat (limited to 'factory')
-rw-r--r-- | factory/django.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/factory/django.py b/factory/django.py index cbf7c10..74e4fdb 100644 --- a/factory/django.py +++ b/factory/django.py @@ -32,8 +32,10 @@ import functools """factory_boy extensions for use with the Django framework.""" try: + import django from django.core import files as django_files except ImportError as e: # pragma: no cover + django = None django_files = None import_failure = e @@ -54,6 +56,18 @@ def require_django(): raise import_failure +if django is None: + def get_model(app, model): + raise import_failure + +elif django.VERSION[:2] < (1, 7): + from django.db.models.loading import get_model + +else: + from django import apps as django_apps + get_model = django_apps.apps.get_model + + class DjangoOptions(base.FactoryOptions): def _build_default_options(self): return super(DjangoOptions, self)._build_default_options() + [ @@ -92,8 +106,7 @@ class DjangoModelFactory(base.Factory): if is_string(definition) and '.' in definition: app, model = definition.split('.', 1) - from django.db.models import loading as django_loading - return django_loading.get_model(app, model) + return get_model(app, model) return definition |