pip install django-rest-tools
pip install https://github.com/quiqueporta/django-rest-tools/tarball/master
views.py:
from django_rest_tools.filters import NearToPointFilter
class LocationsList(generics.ListAPIView):
queryset = Location.objects.all()
serializer_class = LocationListSerializer
filter_backends = (NearToPointFilter,)
point_field_filter = 'location'
We can then filter in the URL.
eg:.
/location/?max_distance=40&lat=-40.4862&long=-0.39536
models.py:
class MyModel(models.Model):
date = models.DateField()
serializers.py:
class MySerializer(serializers.ModelSerializer):
date = DateToTimeStampField()
class Meta:
model = MyModel
fields = ('id', 'date',)
The representation of the serializer is like this:
{
'id': 1,
'date': 1440626400000
}
But into the database stores '2015-08-27'
models.py:
class MyModel(models.Model):
date = models.DateTimeField()
serializers.py:
class MySerializer(serializers.ModelSerializer):
date = DateTimeToTimeStampField()
class Meta:
model = MyModel
fields = ('id', 'date',)
The representation of the serializer is like this:
{
'id': 1,
'date': 1440688376
}
But into the database stores '2015-08-27 15:12:56 UTC'