From 84a4fd3ea11a55441cb5b8acd584c76fc325edcc Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 25 Apr 2011 04:48:55 +0100 Subject: tidy up --- djangorestframework/modelresource.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'djangorestframework/modelresource.py') diff --git a/djangorestframework/modelresource.py b/djangorestframework/modelresource.py index 24fb62ab..a91c79ee 100644 --- a/djangorestframework/modelresource.py +++ b/djangorestframework/modelresource.py @@ -341,6 +341,19 @@ class ModelResource(Resource): return _any(data, self.fields) + def get(self, request, *args, **kwargs): + try: + if args: + # If we have any none kwargs then assume the last represents the primrary key + instance = self.model.objects.get(pk=args[-1], **kwargs) + else: + # Otherwise assume the kwargs uniquely identify the model + instance = self.model.objects.get(**kwargs) + except self.model.DoesNotExist: + raise ErrorResponse(status.HTTP_404_NOT_FOUND) + + return instance + def post(self, request, *args, **kwargs): # TODO: test creation on a non-existing resource url @@ -361,19 +374,6 @@ class ModelResource(Resource): headers['Location'] = instance.get_absolute_url() return Response(status.HTTP_201_CREATED, instance, headers) - def get(self, request, *args, **kwargs): - try: - if args: - # If we have any none kwargs then assume the last represents the primrary key - instance = self.model.objects.get(pk=args[-1], **kwargs) - else: - # Otherwise assume the kwargs uniquely identify the model - instance = self.model.objects.get(**kwargs) - except self.model.DoesNotExist: - raise ErrorResponse(status.HTTP_404_NOT_FOUND) - - return instance - def put(self, request, *args, **kwargs): # TODO: update on the url of a non-existing resource url doesn't work correctly at the moment - will end up with a new url try: -- cgit v1.2.3