From 095e61419e54cd2239f930cf56b6b0c03c30f77a Mon Sep 17 00:00:00 2001 From: David Ray Date: Sat, 11 Feb 2017 17:29:07 -0500 Subject: [PATCH] Fixes #19, add RegexValidator for Location lat_long field --- bakerydemo/locations/models.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bakerydemo/locations/models.py b/bakerydemo/locations/models.py index 52fc311..feed226 100644 --- a/bakerydemo/locations/models.py +++ b/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