Closed ludvikbrodl closed 4 years ago
try:
from rest_framework_gis.fields import GeometryField
class BuildingSerializer(GeoFeatureModelSerializer):
geom = GeometryField()
class Meta:
model = Building
geo_field = "geom"
fields = ("id", "name")
That does work, although I still think that providing geo_field = "geom"
should be enough
It is not trivial to understand this behaviour by just reading the README.
That's probably because the recommended way is to add rest_framework_gis
to INSTALLED_APPS
so that this code is executed: https://github.com/openwisp/django-rest-framework-gis/blob/master/rest_framework_gis/apps.py#L11-L32.
If rest_framework_gis
is not added to INSTALLED_APPS
the definition must be explicit.
Feel free to send a pull request to add further explanation if you think is useful for other people.
If GeoModelSerializer is removed and you are forced to place
rest_framework_gis
in settings.py. This would make all serializers in the project change behaviour to that of GeoModelSerializer, resulting in having to opt out of the behaviour of GEOJSON compatible format for all geometries.Did I miss something or is there no way to use/opt in to the Geojson compatible serializer without settings
rest_framework_gis
in settings.py?I found a quite cumbersome way to accomplish this but it feels hacky:
I would think that just doing:
without rest_framework_gis in
settings.py
would be enough, but this does not output geojson compatible geometriy, but the usual WKT and gives of no warnings.