summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 1aaa44b59..4b663aa23 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2499,6 +2499,8 @@ class Organization(Address, Merge, OwnPerms, ValueGetter):
name = models.CharField(_(u"Name"), max_length=500)
organization_type = models.ForeignKey(OrganizationType,
verbose_name=_(u"Type"))
+ cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
+ db_index=True)
history = HistoricalRecords()
class Meta:
@@ -2519,11 +2521,20 @@ class Organization(Address, Merge, OwnPerms, ValueGetter):
self.town or "")
def __unicode__(self):
+ if self.cached_label:
+ return self.cached_label
+ self.save()
+ return self.cached_label
+
+ def _generate_cached_label(self):
if self.name:
return self.name
- return u"{} - {} - {}".format(self.organization_type,
- self.address or "",
- self.town or "")
+ attrs = ["organization_type", "address", "town"]
+ items = [unicode(getattr(self, attr))
+ for attr in attrs if getattr(self, attr)]
+ if not items:
+ items = [unicode(_(u"unknown organization"))]
+ return u" - ".join(items)
def generate_merge_key(self):
self.merge_key = slugify(self.name if self.name else '')
@@ -2542,6 +2553,9 @@ class Organization(Address, Merge, OwnPerms, ValueGetter):
return slugify(u"-".join(values))
+post_save.connect(cached_label_changed, sender=Organization)
+
+
class PersonType(GeneralType):
class Meta:
verbose_name = _(u"Person type")