A Django REST Framework filter to map ordering query parameters to ORM fields
Project description
drf-ordering-mapper
Small utility for Django REST Framework to map ordering query params to actual ORM fields.
Why?
DRF’s OrderingFilter works well, but you often end up exposing internal field paths like:
?ordering=company__commodity_name
That’s not great for API consumers.
This package lets you do:
?ordering=commodity_name
and map it internally.
Installation
pip install drf-ordering-mapper
Usage
from drf_ordering_mapper.filters import OrderingMapperFilter
class ProductViewSet(ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_backends = [OrderingMapperFilter]
ordering_fields = ['commodity_name', 'price']
ordering_params_mapping = {
'commodity_name': 'company__commodity_name'
}
Example
Request:
GET /api/products?ordering=commodity_name
Internally becomes:
queryset.order_by('company__commodity_name')
Descending:
GET /api/products?ordering=-commodity_name
Multiple fields:
GET /api/products?ordering=commodity_name,-price
Notes
- Works as a drop-in replacement for DRF’s
OrderingFilter - Respects
ordering_fields - Ignores invalid fields (same behavior as DRF)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_ordering_mapper-0.0.1.tar.gz.
File metadata
- Download URL: drf_ordering_mapper-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c05b80fa2823242c1a2affb06d352d40c2f49b9c07e2648121e7e0fc4f54b2e0
|
|
| MD5 |
dbfc5da6d30970e2098f8b2591f204bc
|
|
| BLAKE2b-256 |
479a2d74ed391b620b4ca81956e51ff45e1e42f833210f36fadfd2301bdc3fbc
|
File details
Details for the file drf_ordering_mapper-0.0.1-py3-none-any.whl.
File metadata
- Download URL: drf_ordering_mapper-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11f1537668688246bfeb606466e8bcc2cdae4c02d0e5f8d60432daa8827ac90f
|
|
| MD5 |
5bdb20d8890a2b8f1d4d26c5be0762d2
|
|
| BLAKE2b-256 |
2a8ae65167e79bd82064950fd481b00947f25e2fef581d76eeb5de165f7061e2
|