summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Hunwicks <roger@tonic-solutions.com>2015-04-22 10:06:52 (GMT)
committerRoger Hunwicks <roger@tonic-solutions.com>2015-04-22 10:06:52 (GMT)
commitd63d743510d9529bc5ecd942c21251baff6ab2c8 (patch)
tree1e39e5e2c1c7e0aa1edbc79f1bafbe425b62d8bf
parent818b49ac94b2113d99fa70857b315f39d60b9154 (diff)
downloaddjango-import-export-d63d743510d9529bc5ecd942c21251baff6ab2c8.zip
django-import-export-d63d743510d9529bc5ecd942c21251baff6ab2c8.tar.gz
django-import-export-d63d743510d9529bc5ecd942c21251baff6ab2c8.tar.bz2
All custom Meta attributes to be inherited - see #140
-rw-r--r--import_export/resources.py4
-rw-r--r--tests/core/tests/resources_tests.py14
2 files changed, 16 insertions, 2 deletions
diff --git a/import_export/resources.py b/import_export/resources.py
index 2865aae..a3e42af 100644
--- a/import_export/resources.py
+++ b/import_export/resources.py
@@ -120,7 +120,7 @@ class DeclarativeMetaclass(type):
# Collect the Meta options
options = getattr(base, 'Meta', None)
for option in [option for option in dir(options)
- if option in dir(meta) and not option.startswith('_')]:
+ if not option.startswith('_')]:
setattr(meta, option, getattr(options, option))
# Add direct fields
@@ -138,7 +138,7 @@ class DeclarativeMetaclass(type):
# Add direct options
options = getattr(new_class, 'Meta', None)
for option in [option for option in dir(options)
- if option in dir(meta) and not option.startswith('_')]:
+ if not option.startswith('_')]:
setattr(meta, option, getattr(options, option))
new_class._meta = meta
diff --git a/tests/core/tests/resources_tests.py b/tests/core/tests/resources_tests.py
index be80611..bce7ec3 100644
--- a/tests/core/tests/resources_tests.py
+++ b/tests/core/tests/resources_tests.py
@@ -82,6 +82,20 @@ class ResourceTestCase(TestCase):
['email', 'extra', 'name', 'inherited', 'local'])
self.assertEqual(resource._meta.import_id_fields, ('email',))
+ def test_inheritance_with_custom_attributes(self):
+ class A(MyResource):
+ inherited = fields.Field()
+
+ class Meta:
+ import_id_fields = ('email',)
+ custom_attribute = True
+
+ class B(A):
+ local = fields.Field()
+
+ resource = B()
+ self.assertEqual(resource._meta.custom_attribute, True)
+
class BookResource(resources.ModelResource):
published = fields.Field(column_name='published_date')