diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-16 11:05:51 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-16 11:05:51 +0200 | 
| commit | bca5d1b24b7b434b40edb4809e8e795d643ee63a (patch) | |
| tree | 0f649e6260e309f95b1e362cd2996b3ed09d8bdb /ishtar_common/models.py | |
| parent | b661fc9406cfcdfc9e8dd9c35f27212876bd7263 (diff) | |
| download | Ishtar-bca5d1b24b7b434b40edb4809e8e795d643ee63a.tar.bz2 Ishtar-bca5d1b24b7b434b40edb4809e8e795d643ee63a.zip | |
Town relationship: new fields in db (refs #3753)
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 26 | 
1 files changed, 23 insertions, 3 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index ac5c29a0f..3c2972cab 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -59,7 +59,7 @@ from simple_history.models import HistoricalRecords as BaseHistoricalRecords  from ishtar_common.model_merging import merge_model_objects  from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug,\ -    get_all_field_names, merge_tsvectors +    get_all_field_names, merge_tsvectors, cached_label_changed  from ishtar_common.models_imports import ImporterModel, ImporterType, \      ImporterDefault, ImporterDefaultValues, ImporterColumn, \ @@ -2575,6 +2575,14 @@ class Town(Imported, models.Model):              Department, verbose_name=u"Département", null=True, blank=True)          canton = models.ForeignKey(Canton, verbose_name=u"Canton", null=True,                                     blank=True) +    year = models.IntegerField( +        _("Year of creation"), null=True, blank=True, +        help_text=_("If not filled considered as the older town known.")) +    children = models.ManyToManyField( +        'Town', verbose_name=_(u"Town children"), blank=True, +        related_name='parents') +    cached_label = models.CharField(_(u"Cached name"), max_length=500, +                                    null=True, blank=True, db_index=True)      objects = models.GeoManager()      class Meta: @@ -2584,9 +2592,21 @@ class Town(Imported, models.Model):              ordering = ['numero_insee']      def __unicode__(self): +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self): +        cached_label = self.name          if settings.COUNTRY == "fr": -            return u"%s (%s)" % (self.name, self.numero_insee[:2]) -        return self.name +            cached_label = u"%s - %s" % (self.name, self.numero_insee[:2]) +        if self.year: +            cached_label += " ({})".format(self.year) +        return cached_label + + +post_save.connect(cached_label_changed, sender=Town)  class OperationType(GeneralType): | 
