Add include_fields()
and exclude_fields()
importer methods
for convenience, to tweak field list at runtime
This commit is contained in:
parent
8ae12ca1dc
commit
f9bf01be5a
|
@ -105,9 +105,7 @@ class Importer(object):
|
||||||
self.key = key
|
self.key = key
|
||||||
self.fields = fields or self.supported_fields
|
self.fields = fields or self.supported_fields
|
||||||
if exclude_fields:
|
if exclude_fields:
|
||||||
for field in exclude_fields:
|
self.exclude_fields(*exclude_fields)
|
||||||
if field in self.fields:
|
|
||||||
self.fields.remove(field)
|
|
||||||
if isinstance(self.key, six.string_types):
|
if isinstance(self.key, six.string_types):
|
||||||
self.key = (self.key,)
|
self.key = (self.key,)
|
||||||
if self.key:
|
if self.key:
|
||||||
|
@ -120,6 +118,24 @@ class Importer(object):
|
||||||
self.model_name = self.model_class.__name__
|
self.model_name = self.model_class.__name__
|
||||||
self._setup(**kwargs)
|
self._setup(**kwargs)
|
||||||
|
|
||||||
|
def include_fields(self, *args):
|
||||||
|
"""
|
||||||
|
Add the given fields to the supported field list for the importer. May
|
||||||
|
be used at runtime to customize behavior.
|
||||||
|
"""
|
||||||
|
for field in args:
|
||||||
|
if field not in self.fields:
|
||||||
|
self.fields.append(field)
|
||||||
|
|
||||||
|
def exclude_fields(self, *args):
|
||||||
|
"""
|
||||||
|
Remove the given fields from the supported field list for the importer.
|
||||||
|
May be used at runtime to customize behavior.
|
||||||
|
"""
|
||||||
|
for field in args:
|
||||||
|
if field in self.fields:
|
||||||
|
self.fields.remove(field)
|
||||||
|
|
||||||
def get_model_class(self):
|
def get_model_class(self):
|
||||||
return self.model_class
|
return self.model_class
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue