From a72d4714f15c58a7e09eb3e5eef684052300655f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 16 Jun 2015 13:45:35 +0200 Subject: Import: specialize targetkey (refs #2533) Model: a targetkey connection can now be applied to on particular import (associated_import), one particular user (associated_user) or to all imports (associated_import and associated_user are empty). To be done: change import and forms to fully use this mechanism. --- ishtar_common/models.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 2729aeeef..55b28d4f7 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1206,15 +1206,21 @@ class TargetKey(models.Model): """ User's link between import source and ishtar database. Also temporary used for GeneralType to point missing link before adding - them in ItemKey table + them in ItemKey table. + A targetkey connection can be create to be applied to on particular + import (associated_import), one particular user (associated_user) or to all + imports (associated_import and associated_user are empty). """ target = models.ForeignKey(ImportTarget, related_name='keys') key = models.TextField(_(u"Key")) value = models.TextField(_(u"Value"), blank=True, null=True) is_set = models.BooleanField(_(u"Is set"), default=False) + associated_import = models.ForeignKey('Import', blank=True, null=True) + associated_user = models.ForeignKey('IshtarUser', blank=True, null=True) class Meta: - unique_together = ('target', 'key') + unique_together = ('target', 'key', 'associated_user', + 'associated_import') verbose_name = _(u"Importer - Target key") verbose_name_plural = _(u"Importer - Targets keys") @@ -1376,8 +1382,8 @@ class Import(models.Model): unicode(self.user)) def need_matching(self): - return bool(ImporterType.objects.filter(pk=self.importer_type.pk, - columns__targets__keys__is_set=False).count()) + return bool(TargetKey.objects.filter(associated_import=self, + is_set=False).count()) def get_actions(self): """ -- cgit v1.2.3