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.6.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.6-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf_orderwcast-1.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 a58728073ff9f0cc09eb140625807b18b59fe260c65fc301318cf1595b80fdba
MD5 45f5569810e409275e40f7a8133075f2
BLAKE2b-256 e5f6b1e6831f60513d0c6b0d56dc42f01aecd5b1c8ad2b1d12084eaab86725cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: drf_orderwcast-1.0.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e06bf909254c4f5e5cc262485a36d82b0a3ad47fc6e7eb8e9100d243f10fb4f3
MD5 8fac451948e51af2af8ef28102cc0852
BLAKE2b-256 38201c76339bcde0d17bfdb999634aa325cf50e3c6743029fbe0e8881146bc82

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