summaryrefslogtreecommitdiff
path: root/ishtar_common/data_importer.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-06-18 04:15:51 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-06-18 04:15:51 +0200
commit0db36c5e136bba3048bebbe1fda8f8c55afdec36 (patch)
treec3bfac05e741416a39f2714a7b7e6529e24785d0 /ishtar_common/data_importer.py
parentd7963807b49c45ff2910ec1fc2a0f732540db01b (diff)
downloadIshtar-0db36c5e136bba3048bebbe1fda8f8c55afdec36.tar.bz2
Ishtar-0db36c5e136bba3048bebbe1fda8f8c55afdec36.zip
Import: really prevent from associating not created object to an import
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r--ishtar_common/data_importer.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 33f144d6a..b5fc9b0c6 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -670,7 +670,8 @@ class Importer(object):
for k in data['defaults']:
setattr(t_obj, k, data['defaults'][k])
t_obj.save()
- if self.import_instance and hasattr(t_obj, 'imports'):
+ if self.import_instance and hasattr(t_obj, 'imports') \
+ and created:
t_obj.imports.add(self.import_instance)
for formater, val in self._post_processing:
@@ -834,7 +835,7 @@ class Importer(object):
v, created = model.objects.get_or_create(
**v)
if self.import_instance \
- and hasattr(v, 'imports'):
+ and hasattr(v, 'imports') and created:
v.imports.add(self.import_instance)
m2ms.append((attribute, v))
elif hasattr(field_object, 'rel') and field_object.rel and \
@@ -867,7 +868,8 @@ class Importer(object):
dct = create_dict.copy()
dct['defaults'] = defaults
obj, created = cls.objects.get_or_create(**dct)
- if self.import_instance and hasattr(obj, 'imports'):
+ if self.import_instance and hasattr(obj, 'imports') \
+ and created:
obj.imports.add(self.import_instance)
except IntegrityError as e:
raise IntegrityError(e.message)