Make PinResource orderable by id

Update JavaScript so it orders pins, Fixes #69
This commit is contained in:
Krzysztof Klimonda
2013-02-26 01:21:57 -08:00
parent c1b23b4dd5
commit 82352d6980
3 changed files with 8 additions and 2 deletions

View File

@@ -80,8 +80,8 @@ class PinResource(ModelResource):
class Meta:
fields = ['id', 'url', 'description']
ordering = ['id']
queryset = Pin.objects.all()
resource_name = 'pin'
include_resource_uri = False
authorization = DjangoAuthorization()
ordering = '-published'

View File

@@ -85,6 +85,12 @@ class PinResourceTest(ResourceTestCase):
self.assertEqual(Pin.objects.count(), 3)
self.assertEquals(Tag.objects.count(), 4)
def test_get_list_json_ordered(self):
pin = Pin.objects.latest('id')
response = self.api_client.get('/api/v1/pin/', format='json', data={'order_by': '-id'})
self.assertValidJSONResponse(response)
self.assertEqual(self.deserialize(response)['objects'][0]['id'], pin.id)
def test_get_list_json(self):
user = User.objects.get(pk=1)
image = Image.objects.get(pk=1)

View File

@@ -67,7 +67,7 @@ $(window).load(function() {
$('.spinner').css('display', 'block');
// Fetch our pins from the api using our current offset
var apiUrl = '/api/v1/pin/?format=json&ordering=-id&offset='+String(offset);
var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset);
if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter;
$.get(apiUrl, function(pins) {
// Set which items are editable by the current user