Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18367 -- Allowed LayerMapping to store strings in TextField.

Thanks geoffhing@gmail.com for the report.
  • Loading branch information...
commit f4abba5200e3164003781698c0854383bbc210be 1 parent f1ebcdc
@claudep claudep authored
View
1  django/contrib/gis/tests/layermap/models.py
@@ -17,6 +17,7 @@ class CountyFeat(models.Model):
class City(models.Model):
name = models.CharField(max_length=25)
+ name_txt = models.TextField(default='')
population = models.IntegerField()
density = models.DecimalField(max_digits=7, decimal_places=1)
dt = models.DateField()
View
9 django/contrib/gis/tests/layermap/tests.py
@@ -272,3 +272,12 @@ def test_invalid_layer(self):
lm = LayerMapping(Invalid, invalid_shp, invalid_mapping,
source_srs=4326)
lm.save(silent=True)
+
+ def test_textfield(self):
+ "Tests that String content fits also in a TextField"
+ mapping = copy(city_mapping)
+ mapping['name_txt'] = 'Name'
+ lm = LayerMapping(City, city_shp, mapping)
+ lm.save(silent=True, strict=True)
+ self.assertEqual(City.objects.count(), 3)
+ self.assertEqual(City.objects.all().order_by('name_txt')[0].name_txt, "Houston")
View
2  django/contrib/gis/utils/layermapping.py
@@ -332,7 +332,7 @@ def verify_ogr_field(self, ogr_field, model_field):
val = unicode(ogr_field.value, self.encoding)
else:
val = ogr_field.value
- if len(val) > model_field.max_length:
+ if model_field.max_length and len(val) > model_field.max_length:
raise InvalidString('%s model field maximum string length is %s, given %s characters.' %
(model_field.name, model_field.max_length, len(val)))
elif isinstance(ogr_field, OFTReal) and isinstance(model_field, models.DecimalField):
Please sign in to comment.
Something went wrong with that request. Please try again.