Prechádzať zdrojové kódy

Fixes #19, add RegexValidator for Location lat_long field

David Ray 8 rokov pred
rodič
commit
095e61419e
1 zmenil súbory, kde vykonal 9 pridanie a 1 odobranie
  1. 9 1
      bakerydemo/locations/models.py

+ 9 - 1
bakerydemo/locations/models.py

@@ -1,3 +1,4 @@
+from django.core.validators import RegexValidator
 from django.db import models
 
 from modelcluster.fields import ParentalKey
@@ -92,7 +93,14 @@ class LocationPage(Page):
     lat_long = models.CharField(
         max_length=36,
         help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
-                   Right click Google Maps and click 'What\'s Here'"
+                   Right click Google Maps and click 'What\'s Here'",
+        validators=[
+            RegexValidator(
+                regex='^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$',
+                message='Lat Long must be a comma separated numeric lat and long',
+                code='invalid_lat_long'
+            ),
+        ]
     )
 
     # Search index configuration