Просмотр исходного кода

Add property for numeric address code

This probably should be done with a migration to change the field type
of the existing numeric field, and to correct all values to use the
3-digit form.  However, that would be quite painful, so I have
shamefully opted for the easy way out: provide a simple class property
to format the number in the right way.
master
David Winterbottom 12 лет назад
Родитель
Сommit
11ae85bf10
1 измененных файлов: 6 добавлений и 0 удалений
  1. 6
    0
      oscar/apps/address/abstract_models.py

+ 6
- 0
oscar/apps/address/abstract_models.py Просмотреть файл

@@ -381,6 +381,8 @@ class AbstractCountry(models.Model):
381 381
                                      primary_key=True)
382 382
     iso_3166_1_a3 = models.CharField(_('ISO 3166-1 alpha-3'), max_length=3,
383 383
                                      null=True, db_index=True)
384
+    # This should have been a CharField as it needs to be padded with zeros to
385
+    # be 3 digits.  Access via the numeric_code instead.
384 386
     iso_3166_1_numeric = models.PositiveSmallIntegerField(
385 387
         _('ISO 3166-1 numeric'), null=True, db_index=True)
386 388
     name = models.CharField(_('Official name (CAPS)'), max_length=128)
@@ -402,6 +404,10 @@ class AbstractCountry(models.Model):
402 404
     def __unicode__(self):
403 405
         return self.printable_name or self.name
404 406
 
407
+    @property
408
+    def numeric_code(self):
409
+        return u"%.03d" % self.iso_3166_1_numeric
410
+
405 411
 
406 412
 class AbstractShippingAddress(AbstractAddress):
407 413
     """

Загрузка…
Отмена
Сохранить