summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBojan Mihelac <bmihelac@mihelac.org>2015-04-08 06:37:46 (GMT)
committerBojan Mihelac <bmihelac@mihelac.org>2015-04-08 06:37:46 (GMT)
commit9c915299cac39630cda68b0f817745aa641d001a (patch)
treed4456ad6e5d4ad06f53380116a9780bd440f0fc5
parent7b867686f928071618ac3ec14306a34948f3dcbf (diff)
downloaddjango-import-export-9c915299cac39630cda68b0f817745aa641d001a.zip
django-import-export-9c915299cac39630cda68b0f817745aa641d001a.tar.gz
django-import-export-9c915299cac39630cda68b0f817745aa641d001a.tar.bz2
FIX #200 RelatedObject is removed in Django 1.8
Explicitly check if Django version is 1.8 and use ForeignObjectRel Ref: #224, #228, #229
-rw-r--r--import_export/resources.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/import_export/resources.py b/import_export/resources.py
index ca542d7..798a953 100644
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -8,12 +8,12 @@ import traceback
import tablib
from diff_match_patch import diff_match_patch
+from django import VERSION
from django.utils.safestring import mark_safe
from django.utils import six
from django.db import transaction
from django.db.models.fields import FieldDoesNotExist
from django.db.models.query import QuerySet
-from django.db.models.related import RelatedObject
from django.conf import settings
from .results import Error, Result, RowResult
@@ -24,6 +24,13 @@ from .instance_loaders import (
)
+if VERSION < (1, 8):
+ from django.db.models.related import RelatedObject
+ ForeignObjectRel = RelatedObject
+else:
+ from django.db.models.fields.related import ForeignObjectRel
+ RelatedObject = None
+
try:
from django.utils.encoding import force_text
except ImportError:
@@ -462,14 +469,18 @@ class ModelDeclarativeMetaclass(DeclarativeMetaclass):
# We're not at the last attribute yet, so check that
# we're looking at a relation, and move on to the
# next model.
- if isinstance(f, RelatedObject):
- model = f.model
+ if isinstance(f, ForeignObjectRel):
+ if RelatedObject is None:
+ model = f.related_model
+ else:
+ # Django < 1.8
+ model = f.model
else:
if f.rel is None:
raise KeyError('%s is not a relation' % verbose_path)
model = f.rel.to
- if isinstance(f, RelatedObject):
+ if isinstance(f, ForeignObjectRel):
f = f.field
field = new_class.field_from_django_field(field_name, f,