summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-05-19 18:59:52 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-05-19 18:59:52 +0200
commit43e5926cd40a785d00d56403aeeb5ece3c312e82 (patch)
tree0999b5307d3cdc6d3c3b77f0390dbda9d02fc8ce /ishtar_common/models.py
parent056947701cf49777695b379089fe134bef9678f7 (diff)
downloadIshtar-43e5926cd40a785d00d56403aeeb5ece3c312e82.tar.bz2
Ishtar-43e5926cd40a785d00d56403aeeb5ece3c312e82.zip
Imports: fix many to many association and treatment
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 7514239bd..2dcc99f85 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -975,6 +975,10 @@ MODELS = [
if 'archaeological_files' in settings.INSTALLED_APPS:
MODELS = [('archaeological_files.models.File', _(u"Archaeological files")),
] + MODELS
+if 'archaeological_context_records' in settings.INSTALLED_APPS:
+ MODELS = [('archaeological_context_records.models.ContextRecord',
+ _(u"Archaeological files")),
+ ] + MODELS
def get_model_fields(model):
"""
@@ -1055,15 +1059,21 @@ class ImporterType(models.Model):
return newclass
def get_associated_model(parent_model, keys):
- field = None
- OBJECT_CLS = import_class(parent_model)
+ model = None
+ OBJECT_CLS = None
+ if isinstance(parent_model, unicode) or \
+ isinstance(parent_model, str):
+ OBJECT_CLS = import_class(parent_model)
+ else:
+ OBJECT_CLS = parent_model
for idx, item in enumerate(keys):
if not idx:
field = get_model_fields(OBJECT_CLS)[item]
+ if hasattr(field, 'rel') and hasattr(field.rel, 'to'):
+ model = field.rel.to
else:
- raise NotImplemented()
- if hasattr(field, 'rel') and hasattr(field.rel, 'to'):
- return field.rel.to
+ return get_associated_model(model, keys[1:])
+ return model
class ImporterDefault(models.Model):
"""
@@ -1227,6 +1237,7 @@ class TargetKey(models.Model):
if v:
v.add_key(self.key)
return obj
+
TARGET_MODELS = [
('OrganizationType', _(u"Organization type")),
('SourceType', _(u"Source type")),