-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update DRF field_mapping during initialization
Makes GeoModelSerializer obsolete.
- Loading branch information
1 parent
3a8834e
commit fb6ed36
Showing
7 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
try: | ||
from django.apps import AppConfig as BaseConfig | ||
except ImportError: # django <= 1.6 | ||
class BaseConfig(object): | ||
pass | ||
|
||
|
||
class AppConfig(BaseConfig): | ||
name = 'rest_framework_gis' | ||
|
||
def ready(self): | ||
""" | ||
update Django Rest Framework serializer mappings | ||
""" | ||
from django.contrib.gis.db import models | ||
from rest_framework.serializers import ModelSerializer | ||
from .fields import GeometryField | ||
|
||
try: | ||
# drf 3.0 | ||
field_mapping = ModelSerializer._field_mapping.mapping | ||
except AttributeError: | ||
# drf 3.1 | ||
field_mapping = ModelSerializer.serializer_field_mapping | ||
|
||
# map GeoDjango fields to drf-gis GeometryField | ||
field_mapping.update({ | ||
models.GeometryField: GeometryField, | ||
models.PointField: GeometryField, | ||
models.LineStringField: GeometryField, | ||
models.PolygonField: GeometryField, | ||
models.MultiPointField: GeometryField, | ||
models.MultiLineStringField: GeometryField, | ||
models.MultiPolygonField: GeometryField, | ||
models.GeometryCollectionField: GeometryField | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
try: | ||
from collections import OrderedDict | ||
from collections import OrderedDict # noqa | ||
# python 2.6 | ||
except ImportError: # pragma: no cover | ||
from ordereddict import OrderedDict | ||
from ordereddict import OrderedDict # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters