diff --git a/drop_service/models.py b/drop_service/models.py index c5f20a5..0dd0aad 100644 --- a/drop_service/models.py +++ b/drop_service/models.py @@ -17,7 +17,7 @@ class Drop(ExportModelOperationsMixin('Drop'), models.Model): class Meta: # Force un-prefixed table name for compatibility db_table = 'drops' - get_latest_by = 'created_at' + ordering = ['created_at'] def __repr__(self): return u'<{0} for {1} created at {2} >'.format(self.drop_id, self.message, self.created_at) diff --git a/drop_service/views.py b/drop_service/views.py index 4c05264..ffc6450 100644 --- a/drop_service/views.py +++ b/drop_service/views.py @@ -34,8 +34,6 @@ def _get_drops(self, drop_id): return error('Invalid drop id'), None drops = Drop.objects.filter(drop_id=drop_id) - if not drops: - return HttpResponse(status=status.HTTP_204_NO_CONTENT), None try: have_since, since = self.get_if_modified_since() @@ -45,10 +43,15 @@ def _get_drops(self, drop_id): if have_since: drops = drops.filter(created_at__gt=since) - if have_since and not drops: - return HttpResponseNotModified(), None - return None, drops + + if not drops.exists(): + if have_since: + return HttpResponseNotModified(), None + else: + return HttpResponse(status=status.HTTP_204_NO_CONTENT), None + + return None, list(drops) def get(self, request, drop_id): response, drops = self._get_drops(drop_id) @@ -61,7 +64,7 @@ def get(self, request, drop_id): body = self.generate_body(drops, boundary) response = HttpResponse(body, content_type=content_type) if drops: - self.set_latest(response, drops.latest()) + self.set_latest(response, drops[-1]) return response def head(self, request, drop_id):