summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-04 13:46:50 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-04 13:46:50 +0100
commite62d26f17f7f0da10d7bf0f9c7d8895c88002021 (patch)
tree6a0f36c3476574e7eb80ce08f9a1a513b2b31da3
parentc17f21d49c54514f6945d95b010cbb237d724ca8 (diff)
downloadIshtar-e62d26f17f7f0da10d7bf0f9c7d8895c88002021.tar.bz2
Ishtar-e62d26f17f7f0da10d7bf0f9c7d8895c88002021.zip
Imports: adapt auto model creation for importers to new importer model
-rw-r--r--ishtar_common/data_importer.py5
-rw-r--r--ishtar_common/models.py2
-rw-r--r--ishtar_common/tests.py4
3 files changed, 8 insertions, 3 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 49705f0df..de4883c69 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -640,6 +640,9 @@ class Importer(object):
model_name = self.OBJECT_CLS.__module__ + '.' + \
self.OBJECT_CLS.__name__
+ model_cls, c = models.ImporterModel.object.get_or_create(
+ klass=model_name, default={'name': self.OBJECT_CLS.__name__}
+ )
unicity_keys = ''
if self.UNICITY_KEYS:
@@ -647,7 +650,7 @@ class Importer(object):
importer = models.ImporterType.objects.create(
slug=self.SLUG, name=name, description=self.DESC,
- associated_models=model_name, unicity_keys=unicity_keys)
+ associated_models=model_cls, unicity_keys=unicity_keys)
for default in self.DEFAULTS:
values = self.DEFAULTS[default]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 7b596d209..6e655776d 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1756,7 +1756,7 @@ class ImporterType(models.Model):
blank=True, null=True)
associated_models = models.ForeignKey(
ImporterModel, verbose_name=_(u"Associated model"),
- related_name='+', blank=True, null=True)
+ related_name='+', blank=True, null=True)
created_models = models.ManyToManyField(
ImporterModel, verbose_name=_(u"Models that can accept new items"),
blank=True, null=True, help_text=_(u"Leave blank for no restrictions"),
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index b57ff0a94..a2d7bf46c 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -771,8 +771,10 @@ class ImportTest(TestCase):
# create an import, fields are not relevant...
create_user()
+ imp_model = models.ImporterModel.objects.create(
+ klass='ishtar_common.models.Person', name='Person')
importer_type = models.ImporterType.objects.create(
- associated_models='ishtar_common.models.Person')
+ associated_models=imp_model)
mcc_operation_file = DjangoFile(file(
settings.ROOT_PATH +
'../archaeological_operations/tests/MCC-operations-example.csv',