summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKane <kane-c@users.noreply.github.com>2014-11-28 01:42:53 (GMT)
committerKane <kane-c@users.noreply.github.com>2014-11-28 01:42:53 (GMT)
commita271df7554fcb1cbe9dd76b9157f8cd201f332d8 (patch)
tree0a2c4fe3f4200ae1486c7ac0d5f27a9ad1e9906a
parentce012de4542e59a080dceca51c061b5695444573 (diff)
downloaddjango-import-export-a271df7554fcb1cbe9dd76b9157f8cd201f332d8.zip
django-import-export-a271df7554fcb1cbe9dd76b9157f8cd201f332d8.tar.gz
django-import-export-a271df7554fcb1cbe9dd76b9157f8cd201f332d8.tar.bz2
Allow using a field on a one to one relation
Fixes the error when trying to export a field from a one-to-one relationship (e.g. `profile__newsletter` on a user model).
-rw-r--r--import_export/resources.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/import_export/resources.py b/import_export/resources.py
index 4c6a01c..717240b 100644
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -461,9 +461,12 @@ 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 f.rel is None:
- raise KeyError('%s is not a relation' % verbose_path)
- model = f.rel.to
+ if isinstance(f, RelatedObject):
+ 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):
f = f.field