Преглед изворни кода

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 година
родитељ
комит
11ae85bf10
1 измењених фајлова са 6 додато и 0 уклоњено
  1. 6
    0
      oscar/apps/address/abstract_models.py

+ 6
- 0
oscar/apps/address/abstract_models.py Прегледај датотеку

381
                                      primary_key=True)
381
                                      primary_key=True)
382
     iso_3166_1_a3 = models.CharField(_('ISO 3166-1 alpha-3'), max_length=3,
382
     iso_3166_1_a3 = models.CharField(_('ISO 3166-1 alpha-3'), max_length=3,
383
                                      null=True, db_index=True)
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
     iso_3166_1_numeric = models.PositiveSmallIntegerField(
386
     iso_3166_1_numeric = models.PositiveSmallIntegerField(
385
         _('ISO 3166-1 numeric'), null=True, db_index=True)
387
         _('ISO 3166-1 numeric'), null=True, db_index=True)
386
     name = models.CharField(_('Official name (CAPS)'), max_length=128)
388
     name = models.CharField(_('Official name (CAPS)'), max_length=128)
402
     def __unicode__(self):
404
     def __unicode__(self):
403
         return self.printable_name or self.name
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
 class AbstractShippingAddress(AbstractAddress):
412
 class AbstractShippingAddress(AbstractAddress):
407
     """
413
     """

Loading…
Откажи
Сачувај