Skip to main content

A Django REST Framework OrderingFilter like class that handles sort with casting

Project description

drf-orderwcast

OrderingFilter subclass that applies functions before sorting the declared fields.

Installing

  1. pip install drf-orderwcast;

  2. Add drf_orderwcast in INSTALLED_APPS of settings.py file.

Using

Use inplace of OrderingFilter in views. Needs to tell the functions in a dictionary of field name and database functions.

views.py

from django.db.models.functions import Lower

from drf_orderwcast import OrderingWCastFilter


class FooListView(generics.ListAPIView):
    queryset = Foo.objects.all()
    serializer_class = FooSerializer
    filter_backends = (OrderingWCastFilter,)
    ordering_fields = ['name', 'email']
    ordering_cast = {'name': Lower('name')}

In the example above, the name field included in ordering_cast property will now have case-consistent ordering. email continues to be sorted as it would be when using the standard OrderingFilter class from filters module.

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

drf_orderwcast-1.0.7.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_orderwcast-1.0.7-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file drf_orderwcast-1.0.7.tar.gz.

File metadata

  • Download URL: drf_orderwcast-1.0.7.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.18

File hashes

Hashes for drf_orderwcast-1.0.7.tar.gz
Algorithm Hash digest
SHA256 c4bccddd462dd60d50ffffb47408d5c23e6e5c08944a4e81f24a1691a7bcff6a
MD5 30a1b4483256cf8710e1376481f4497f
BLAKE2b-256 f05b13593311194c9ad1a9bbef7b62e5f16e509181cbba2af1fa16fbcbed7150

See more details on using hashes here.

File details

Details for the file drf_orderwcast-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: drf_orderwcast-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.18

File hashes

Hashes for drf_orderwcast-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fc8a14e833b47a7eeb19c1de084205773f9ede16c4878dbd1e9143ec4ea9ba9c
MD5 84a6f7959834c9338d275133c11c3529
BLAKE2b-256 ce7691f8a909a94981ea1c16bfb4097a58e4fde2b3536eda70fd7f23ff9318e6

See more details on using hashes here.

Supported by

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