aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/modelresource.py
diff options
context:
space:
mode:
authorTom Christie2011-04-25 04:48:55 +0100
committerTom Christie2011-04-25 04:48:55 +0100
commit84a4fd3ea11a55441cb5b8acd584c76fc325edcc (patch)
tree5ef40c22379166cfb58b3c45190e9ba60f006fdd /djangorestframework/modelresource.py
parent4692374e0d6f020f8a7a95f3a60094d525c59341 (diff)
downloaddjango-rest-framework-84a4fd3ea11a55441cb5b8acd584c76fc325edcc.tar.bz2
tidy up
Diffstat (limited to 'djangorestframework/modelresource.py')
-rw-r--r--djangorestframework/modelresource.py26
1 files changed, 13 insertions, 13 deletions
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: