Skip to content

Commit

Permalink
Merge pull request #134 from AltSchool/fix/no-defer-on-delete
Browse files Browse the repository at this point in the history
Exclude delete requests from having fields deferred
  • Loading branch information
aleontiev authored Oct 13, 2016
2 parents 879f4a4 + e95c357 commit 3407f1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dynamic_rest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,11 @@ def _filter_queryset(
# use requirements at this level to limit fields selected
# only do this for GET requests where we are not requesting the
# entire fieldset
if '*' not in requirements and not self.view.is_update():
if (
'*' not in requirements and
not self.view.is_update() and
not self.view.is_delete()
):
id_fields = getattr(serializer, 'get_id_fields', lambda: [])()
# only include local model fields
only = [
Expand Down
10 changes: 10 additions & 0 deletions dynamic_rest/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dynamic_rest.renderers import DynamicBrowsableAPIRenderer

UPDATE_REQUEST_METHODS = ('PUT', 'PATCH', 'POST')
DELETE_REQUEST_METHOD = 'DELETE'


class QueryParams(QueryDict):
Expand Down Expand Up @@ -240,6 +241,15 @@ def is_update(self):
else:
return False

def is_delete(self):
if (
self.request and
self.request.method.upper() == DELETE_REQUEST_METHOD
):
return True
else:
return False

def get_serializer(self, *args, **kwargs):
if 'request_fields' not in kwargs:
kwargs['request_fields'] = self.get_request_fields()
Expand Down

0 comments on commit 3407f1f

Please sign in to comment.