Browse Source

Add min and max length option for postcode

Josué Tille 6 years ago
parent
commit
9d2b6e03de
2 changed files with 4 additions and 3 deletions
  1. 2 2
      coin/members/models.py
  2. 2 1
      coin/settings_base.py

+ 2 - 2
coin/members/models.py

@@ -99,8 +99,8 @@ class Member(CoinLdapSyncMixin, AbstractUser):
     # support more countries and address types)
     address = models.TextField(
         verbose_name='adresse postale', blank=True, null=True)
-    postal_code = models.CharField(max_length=settings.POSTCODE_LENGTH, blank=True, null=True,
-                                   validators=[RegexValidator(regex=r'^\d{' + str(settings.POSTCODE_LENGTH) + r'}$',
+    postal_code = models.CharField(max_length=settings.POSTCODE_MAX_LENGTH, blank=True, null=True,
+                                   validators=[RegexValidator(regex=r'^\d{' + str(settings.POSTCODE_MIN_LENGTH) + r',' + str(settings.POSTCODE_MAX_LENGTH) + r'}$',
                                                               message='Code postal non valide.')],
                                    verbose_name='code postal')
     city = models.CharField(max_length=200, blank=True, null=True,

+ 2 - 1
coin/settings_base.py

@@ -58,7 +58,8 @@ USE_L10N = True
 USE_TZ = True
 
 # Postcode length
-POSTCODE_LENGTH = 5
+POSTCODE_MIN_LENGTH = 5
+POSTCODE_MAX_LENGTH = 5
 
 # Default country
 DEFAULT_COUNTRY = "France"