-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: DRF issue #6886 with StableOrderingFilter
- Loading branch information
1 parent
af75ce5
commit 5ea315b
Showing
8 changed files
with
26 additions
and
7 deletions.
There are no files selected for viewing
Binary file removed
BIN
-304 KB
example/media/images/block_templates_previews/carousel_home_unical.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.core.exceptions import FieldError | ||
from rest_framework.filters import OrderingFilter | ||
|
||
|
||
# Work around DRF issue #6886 by always adding the primary key as last order field. | ||
class StableOrderingFilter(OrderingFilter): | ||
def get_ordering(self, request, queryset, view): | ||
ordering = super(StableOrderingFilter, self).get_ordering(request, queryset, view) | ||
pk = queryset.model._meta.pk.name | ||
if ordering is None: return [pk,] | ||
for field in queryset.model._meta.fields: | ||
if field.__dict__['name'] == 'order': | ||
return list(ordering) + ['order', pk,] | ||
return list(ordering) + [pk,] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters