summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome M. BERGER <jerome.berger@sagemcom.com>2015-02-24 08:08:16 (GMT)
committerJerome M. BERGER <jerome.berger@sagemcom.com>2015-02-24 08:08:16 (GMT)
commita5504b3117b3b4ffdb7ff752f5ccd35a9bbe00c8 (patch)
treef4c7cbcc5b79b94c81cfe20daa69814c809ea138
parent816ddfddb07f6d57ffdc612d9988cb2c148775a9 (diff)
downloaddjango-import-export-a5504b3117b3b4ffdb7ff752f5ccd35a9bbe00c8.zip
django-import-export-a5504b3117b3b4ffdb7ff752f5ccd35a9bbe00c8.tar.gz
django-import-export-a5504b3117b3b4ffdb7ff752f5ccd35a9bbe00c8.tar.bz2
Automatically add missing fields to the end of `export_order`. Fixes #210.
-rw-r--r--import_export/resources.py3
-rw-r--r--tests/core/tests/resources_tests.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/import_export/resources.py b/import_export/resources.py
index 3663ee4..ca542d7 100644
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -371,7 +371,8 @@ class Resource(six.with_metaclass(DeclarativeMetaclass)):
return result
def get_export_order(self):
- return self._meta.export_order or self.fields.keys()
+ order = tuple (self._meta.export_order or ())
+ return order + tuple (k for k in self.fields.keys() if k not in order)
def export_field(self, field, obj):
field_name = self.get_field_name(field)
diff --git a/tests/core/tests/resources_tests.py b/tests/core/tests/resources_tests.py
index b3901d5..bbaee0b 100644
--- a/tests/core/tests/resources_tests.py
+++ b/tests/core/tests/resources_tests.py
@@ -33,6 +33,7 @@ except ImportError:
class MyResource(resources.Resource):
name = fields.Field()
email = fields.Field()
+ extra = fields.Field()
class Meta:
export_order = ('email', 'name')
@@ -57,7 +58,7 @@ class ResourceTestCase(TestCase):
def test_get_export_order(self):
self.assertEqual(self.my_resource.get_export_headers(),
- ['email', 'name'])
+ ['email', 'name', 'extra'])
class BookResource(resources.ModelResource):