encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
28.23k stars 6.82k forks source link

serializations for geodjango geometry #29

Closed olivierboudet closed 11 years ago

olivierboudet commented 13 years ago

I am trying to use django-rest-framework for a geographic data API in a geodjango project.

In geodjango, a geometry is an instance of GEOSGeometry which can be serialized with differents properties such as GEOSGeometry.json or GEOSGeometry.wkt (seems to be the default behavior).

With django-rest-framework, a call to the api with "_accept=application/json" always returns a WKT string (the default) instead of a json string.

tomchristie commented 13 years ago

Is there any chance you'd be able to provide a simple test for the current and the expected behavior? (Ideally fork the project and add it to the existing tests.) I'd be very happy to see this fixed, but it'll likely stay low priority otherwise.

dmeehan commented 11 years ago

What would need to happen in order to add support for GEOSGeometry fields? I'm new to django-rest-framework, but I'm interested in taking a look a how to implement. Tastypie has built support for this by creating a GeometryApiField which is a subclass of their ApiField. (https://github.com/philipn/django-tastypie/blob/gis/tastypie/contrib/gis/resources.py). What would be the equivalent for DRF?

tomchristie commented 11 years ago

@dmeehan - The same thing really. Override WriteableField, and implement appropriate to_native and from_native methods.

dmeehan commented 11 years ago

I've started a project that will act as a GeoDjango enabled plugin to DRF.

https://github.com/dmeehan/django-rest-framework-gis

I've written a GeometryField implementation of WritableField and will be working to implement additional features.

@tomchristie, I'd like to get your insight on the best way to tackle this issue:

https://github.com/dmeehan/django-rest-framework-gis/issues/2

I'm thinking perhaps as a renderer? I'm still trying to figure out how all the pieces of DRF fit together to produce the output.

tomchristie commented 11 years ago

Given https://github.com/dmeehan/django-rest-framework-gis and https://github.com/mjumbewu/django-rest-framework-gis, I'm going to close this ticket for now. My preference is for Geo integration to be a third-party concern. That might change in the future, but on balance it seems like the best option right now.