Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization of properties holding None values #85

Merged
merged 1 commit into from
Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion rest_framework_gis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def get_properties(self, instance, fields):
if field.write_only:
continue
value = field.get_attribute(instance)
properties[field.field_name] = field.to_representation(value)
value_repr = None
if value is not None:
value_repr = field.to_representation(value)
properties[field.field_name] = value_repr

return properties

Expand Down
1 change: 1 addition & 0 deletions tests/django_restframework_gis_tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class BaseModel(models.Model):
name = models.CharField(max_length=32)
slug = models.SlugField(max_length=128, unique=True, blank=True)
timestamp = models.DateTimeField(null=True, blank=True)
geometry = models.GeometryField()
objects = models.GeoManager()

Expand Down
4 changes: 2 additions & 2 deletions tests/django_restframework_gis_tests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Meta:
model = Location
geo_field = 'geometry'
id_field = 'slug'
fields = ('name', 'slug')
fields = ('name', 'slug', 'timestamp')


class LocationGeoFeatureFalseIdSerializer(LocationGeoFeatureSerializer):
Expand Down Expand Up @@ -98,7 +98,7 @@ class Meta:
model = BoxedLocation
geo_field = 'geometry'
bbox_geo_field = 'bbox_geometry'
fields = ['name', 'details', 'id']
fields = ['name', 'details', 'id', 'timestamp']


class LocationGeoFeatureBboxSerializer(gis_serializers.GeoFeatureModelSerializer):
Expand Down
1 change: 1 addition & 0 deletions tests/django_restframework_gis_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def test_geojson_format(self):
'details': "http://testserver/geojson/%s/" % location.id,
'name': 'geojson test',
'fancy_name': 'Kool geojson test',
'timestamp': None,
'slug': 'geojson-test',
},
'geometry': {
Expand Down