Skip to content

Commit

Permalink
chore: documentation ordering fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MizzleLizzle authored and coronoro committed Sep 18, 2024
1 parent ea0ab17 commit 00b3eac
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,21 @@ class BookViewSet(GenericViewSet, AggregationMixin):
```
You can use 'lt', 'lte', 'gt', 'gte', 'exact' and __all__ as values for the **aggregated_filtering_fields** class variable.

To order the queryset, you can use the standard Django ordering filter.

Fields available for ordering the result are taken from the `aggregated_ordering_fields` attribute.
```python
class BookViewSet(GenericViewSet, AggregationMixin):
queryset = Book.objects.all()
serializer_class = BookSerializer
ordering_fields = ['value', 'grouped_by_field']
aggregated_ordering_fields = ['value', 'grouped_by_field']
```

if this is not set available fields are taken from the usual `ordering_fields` attribute.
The reason for this behaviour is to accommodate interplay with the often used `OrderingFilter`
```python
class BookViewSet(GenericViewSet, AggregationMixin):
queryset = Book.objects.all()
serializer_class = BookSerializer
ordering_fields = ['page_count', 'author']
```
If no ordering fields of any kind are specified or the list contains `"__all__"` any passed ordering will be tried to be applied.
``ordering_fields = __all__`` is also possible.

0 comments on commit 00b3eac

Please sign in to comment.