Sort currency API

This commit is contained in:
Oliver Walters 2019-09-07 19:28:20 +10:00
parent 873faee040
commit 6752bdc1c6
2 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ Provides a JSON API for common components.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from rest_framework import permissions, generics from rest_framework import permissions, generics, filters
from django.conf.urls import url from django.conf.urls import url
@ -27,7 +27,11 @@ class CurrencyList(generics.ListCreateAPIView):
permissions.IsAuthenticated, permissions.IsAuthenticated,
] ]
ordering_fields = ['name', 'value'] filter_backends = [
filters.OrderingFilter,
]
ordering_fields = ['suffix', 'value']
common_api_urls = [ common_api_urls = [

View File

@ -15,6 +15,9 @@
$("#currency-table").bootstrapTable({ $("#currency-table").bootstrapTable({
url: "{% url 'api-currency-list' %}", url: "{% url 'api-currency-list' %}",
queryParams: {
ordering: 'suffix'
},
sortable: true, sortable: true,
search: true, search: true,
formatNoMatches: function() { return "No currencies found"; }, formatNoMatches: function() { return "No currencies found"; },
@ -38,14 +41,17 @@
{ {
field: 'suffix', field: 'suffix',
title: 'Currency', title: 'Currency',
sortable: true,
}, },
{ {
field: 'description', field: 'description',
title: 'Description', title: 'Description',
sortable: true,
}, },
{ {
field: 'value', field: 'value',
title: 'Value', title: 'Value',
sortable: true,
} }
] ]
}); });