Skip to main content

Tools for Django Rest Framework

Project description

Build Status Coverage Status Requirements Status

Install last stable version from pypi

pip install django-rest-tools

Install development version

pip install https://github.com/quiqueporta/django-rest-tools/tarball/master

Filters

NearToPointFilter

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

Fields

DateToTimeStampField

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’

DateTimeToTimeStampField

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’

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-rest-tools-1.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-rest-tools-1.1.tar.gz.

File metadata

File hashes

Hashes for django-rest-tools-1.1.tar.gz
Algorithm Hash digest
SHA256 5068d446832c85987a9319938f3ccf0a419a6218295e5d5a34d75dc1f6ec2da0
MD5 da573804159d1176bea07dae476d5679
BLAKE2b-256 f0e7fb3c5355937f7ed7d52e361ce503f084244cb0376acb35dbb6aa55d2b594

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page