diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/admin.py | 3 | ||||
-rw-r--r-- | ishtar_common/migrations/0071_auto_20180926_1023.py | 25 | ||||
-rw-r--r-- | ishtar_common/models.py | 17 |
3 files changed, 42 insertions, 3 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 5a8afb416..6ae455e53 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -480,7 +480,8 @@ for model in general_models: class AreaAdmin(GeneralTypeAdmin): - list_display = ('label', 'parent', 'available') + list_display = ('label', 'reference', 'parent', 'available') + search_fields = ('label', 'reference') list_filter = ('parent',) model = models.Area form = make_ajax_form( diff --git a/ishtar_common/migrations/0071_auto_20180926_1023.py b/ishtar_common/migrations/0071_auto_20180926_1023.py new file mode 100644 index 000000000..c508981ca --- /dev/null +++ b/ishtar_common/migrations/0071_auto_20180926_1023.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-09-26 10:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0070_profiletypesummary'), + ] + + operations = [ + migrations.AddField( + model_name='area', + name='reference', + field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Reference'), + ), + migrations.AlterField( + model_name='jsondatafield', + name='value_type', + field=models.CharField(choices=[(b'T', 'Text'), (b'LT', 'Long text'), (b'I', 'Integer'), (b'B', 'Boolean'), (b'F', 'Float'), (b'D', 'Date'), (b'C', 'Choices')], default=b'T', max_length=10, verbose_name='Type'), + ), + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 07b4002ff..e862885d0 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3808,8 +3808,14 @@ class Town(Imported, models.Model): def _generate_cached_label(self): cached_label = self.name - if settings.COUNTRY == "fr": - cached_label = u"%s - %s" % (self.name, self.numero_insee[:2]) + if settings.COUNTRY == "fr" and self.numero_insee: + dpt_len = 2 + if self.numero_insee.startswith('97') or \ + self.numero_insee.startswith('98') or \ + self.numero_insee[0] not in ('0', '1', '2', '3', '4', '5', + '6', '7', '8', '9'): + dpt_len = 3 + cached_label = u"%s - %s" % (self.name, self.numero_insee[:dpt_len]) if self.year and self.children.count(): cached_label += u" ({})".format(self.year) return cached_label @@ -3838,6 +3844,8 @@ m2m_changed.connect(town_child_changed, sender=Town.children.through) class Area(HierarchicalType): towns = models.ManyToManyField(Town, verbose_name=_(u"Towns"), blank=True, related_name='areas') + reference = models.CharField(_(u"Reference"), max_length=200, blank=True, + null=True) parent = models.ForeignKey( 'self', blank=True, null=True, verbose_name=_(u"Parent"), help_text=_(u"Only four level of parent are managed."), @@ -3849,6 +3857,11 @@ class Area(HierarchicalType): verbose_name_plural = _(u"Areas") ordering = ('parent__label', 'label') + def __unicode__(self): + if not self.reference: + return self.label + return u"{} ({})".format(self.label, self.reference) + class OperationType(GeneralType): order = models.IntegerField(_(u"Order"), default=1) |