Skip to content

Commit

Permalink
Add support for point serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
edelvalle committed Mar 27, 2017
1 parent d34abd6 commit 2dbdd9a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions carbon14/django.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from xoutil.decorator.meta import decorator
from xoutil.objects import get_first_of

from django.conf import settings
from django.utils import timezone
from django.contrib.gis.geos import Point

from rest_framework.response import Response
from rest_framework.views import APIView
Expand Down Expand Up @@ -76,3 +78,11 @@ def serialize(self, instance, children, **kwargs):
value = super().serialize(instance, children, **kwargs)
value = value and timezone.localtime(value)
return value


class PointField(Field):
def serialize(self, instance, *args, **kwargs):
value = get_first_of(instance, self.attr)
if isinstance(value, Point):
value = tuple(value)
return value

0 comments on commit 2dbdd9a

Please sign in to comment.