-
Notifications
You must be signed in to change notification settings - Fork 202
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
TypeError: Cannot set GeoPoint SpatialProxy (POINT) with value of type: <class 'dict'> #284
Comments
I got the same issue with : Note : those versions are not officially supported. |
A quick solution is to redefine a new serializer class that correctly instantiate a GEOSGeometry. Here is such a class : class InstantiatingGeoFeatureModelSerializer(GeoFeatureModelSerializer):
def to_internal_value(self, data):
result = super().to_internal_value(data)
result[self.Meta.geo_field] = GEOSGeometry(
json.dumps(result[self.Meta.geo_field])
)
return result |
@nemesifier is it in the scope of this library to merge such a fix ? I am willing to make a PR supporting this use-case. |
Ok, the best way to solve this is to implement "validate_<your_geometry_field>" and to instatiate a For example : class PolySerializer(GeoFeatureModelSerializer):
class Meta:
model = Poly
geo_field = "geom"
fields = ("id", "name", "created_at")
read_only_fields = ["id"]
def validate_geom(self, value):
value = GEOSGeometry(json.dumps(value))
# The following line is not related to this issue, but it's usefull if your geometry field is a multi-collection
if isinstance(value, Polygon):
value = MultiPolygon(value)
return value |
I am working with Django, Django Rest Framework, Django Rest Framework GIS and POSTgis database to create an endpoint that should upload a geografical point and all its related information. I have defined a Model, Serializer and View for that purpose. But when making a request using postman I am getting the following error:
TypeError: Cannot set GeoPoint SpatialProxy (POINT) with value of type: <class 'dict'>
I am currently working with:
Model definition:
Serializer:
View:
This is the image of the POSTman request:
And this is the complete error:
The text was updated successfully, but these errors were encountered: