Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tomchristie/django-rest-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Jul 22, 2015
2 parents f9c61e8 + cab9818 commit 762a30d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 0 additions & 2 deletions docs/tutorial/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ Rather than write multiple views we're grouping together all the common behavior

We can easily break these down into individual views if we need to, but using viewsets keeps the view logic nicely organized as well as being very concise.

For trivial cases you can simply set a `model` attribute on the `ViewSet` class and the serializer and queryset will be automatically generated for you. Setting the `queryset` and/or `serializer_class` attributes gives you more explicit control of the API behaviour, and is the recommended style for most applications.

## URLs

Okay, now let's wire up the API URLs. On to `tutorial/urls.py`...
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-optionals.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Optional packages which may be used with REST framework.
markdown==2.5.2
django-guardian==1.2.5
django-guardian==1.3.0
django-filter==0.10.0
5 changes: 4 additions & 1 deletion rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,7 @@ def filter_queryset(self, request, queryset, view):
'model_name': get_model_name(model_cls)
}
permission = self.perm_format % kwargs
return guardian.shortcuts.get_objects_for_user(user, permission, queryset)
if guardian.VERSION >= (1, 3):
# Maintain behavior compatibility with versions prior to 1.3
extra = {'accept_global_perms': False}
return guardian.shortcuts.get_objects_for_user(user, permission, queryset, **extra)
20 changes: 20 additions & 0 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ def save(self, **kwargs):
'You cannot call `.save()` on a serializer with invalid data.'
)

# Guard against incorrect use of `serializer.save(commit=False)`
assert 'commit' not in kwargs, (
"'commit' is not a valid keyword argument to the 'save()' method. "
"If you need to access data before committing to the database then "
"inspect 'serializer.validated_data' instead. "
"You can also pass additional keyword arguments to 'save()' if you "
"need to set extra attributes on the saved model instance. "
"For example: 'serializer.save(owner=request.user)'.'"
)

validated_data = dict(
list(self.validated_data.items()) +
list(kwargs.items())
Expand Down Expand Up @@ -611,6 +621,16 @@ def save(self, **kwargs):
"""
Save and return a list of object instances.
"""
# Guard against incorrect use of `serializer.save(commit=False)`
assert 'commit' not in kwargs, (
"'commit' is not a valid keyword argument to the 'save()' method. "
"If you need to access data before committing to the database then "
"inspect 'serializer.validated_data' instead. "
"You can also pass additional keyword arguments to 'save()' if you "
"need to set extra attributes on the saved model instance. "
"For example: 'serializer.save(owner=request.user)'.'"
)

validated_data = [
dict(list(attrs.items()) + list(kwargs.items()))
for attrs in self.validated_data
Expand Down

0 comments on commit 762a30d

Please sign in to comment.