From b5d80cdc056efa4c15f0d8f08e237fc324b691e2 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 28 Oct 2017 17:23:51 +0200 Subject: Towns: manage natural keys --- ishtar_common/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ishtar_common') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 5dd9ddee1..f0552d3eb 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2657,6 +2657,11 @@ if settings.COUNTRY == 'fr': (self.name, unicode(self.arrondissement))) +class TownManager(models.Manager): + def get_by_natural_key(self, numero_insee, year): + return self.get(numero_insee=numero_insee, year=year) + + class Town(Imported, models.Model): name = models.CharField(_(u"Name"), max_length=100) surface = models.IntegerField(_(u"Surface (m2)"), blank=True, null=True) @@ -2685,6 +2690,9 @@ class Town(Imported, models.Model): ordering = ['numero_insee'] unique_together = (('numero_insee', 'year'),) + def natural_key(self): + return (self.numero_insee, self.year) + def __unicode__(self): if self.cached_label: return self.cached_label -- cgit v1.2.3