Metadata-Version: 2.4
Name: drf-orderwcast
Version: 1.0.6
Summary: A Django REST Framework OrderingFilter like class that handles sort with casting
Home-page: https://github.com/keter2002/drf-orderwcast
Author: João Manica
Author-email: joaoedisonmanica@gmail.com
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: djangorestframework
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# 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

```python

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.
