aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/modelresource.py
diff options
context:
space:
mode:
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: