diff options
| author | Tom Christie | 2012-01-21 17:58:06 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-01-21 17:58:06 +0000 |
| commit | add6c88a265858a6c9943e5cc73b22e2866c98b9 (patch) | |
| tree | af9df7188eb5df2522cbd45bd869c3ec83832cb8 /djangorestframework/mixins.py | |
| parent | c94423151b5e135c5d977d63a7092cc4a8ab5de4 (diff) | |
| parent | 417eacb2eda46feec0e8fb7fac5eb3131ab996f8 (diff) | |
| download | django-rest-framework-add6c88a265858a6c9943e5cc73b22e2866c98b9.tar.bz2 | |
Merge https://github.com/mjumbewu/django-rest-framework
Diffstat (limited to 'djangorestframework/mixins.py')
| -rw-r--r-- | djangorestframework/mixins.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index c7f7b10c..66ab9071 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -557,6 +557,13 @@ class ModelMixin(object): return all_kw_args + def get_object(self, *args, **kwargs): + """ + Get the instance object for read/update/delete requests. + """ + model = self.resource.model + return model.objects.get(self.build_query(*args, **kwargs)) + class ReadModelMixin(ModelMixin): """ @@ -566,7 +573,7 @@ class ReadModelMixin(ModelMixin): model = self.resource.model try: - self.model_instance = model.objects.get(self.build_query(*args, **kwargs)) + self.model_instance = self.get_object(*args, **kwargs) except model.DoesNotExist: raise ErrorResponse(status.HTTP_404_NOT_FOUND) @@ -629,7 +636,7 @@ class UpdateModelMixin(ModelMixin): # 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: - self.model_instance = model.objects.get(self.build_query(*args, **kwargs)) + self.model_instance = self.get_object(*args, **kwargs) for (key, val) in self.CONTENT.items(): setattr(self.model_instance, key, val) @@ -647,7 +654,7 @@ class DeleteModelMixin(ModelMixin): model = self.resource.model try: - instance = model.objects.get(self.build_query(*args, **kwargs)) + instance = self.get_object(*args, **kwargs) except model.DoesNotExist: raise ErrorResponse(status.HTTP_404_NOT_FOUND, None, {}) @@ -689,7 +696,7 @@ class ListModelMixin(ModelMixin): def get_queryset(self): model = self.resource.model - return model.objects.all() if self.queryset is None else self.queryset + return model.objects.all() if self.queryset is None else self.queryset ########## Pagination Mixins ########## |
