mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
Merge pull request #349 from ZestCore/master
Documentation Fix for Auth/Throttling API guide + 'from_native' bug
This commit is contained in:
commit
204db7bdaa
|
@ -30,7 +30,7 @@ The default authentication policy may be set globally, using the `DEFAULT_AUTHEN
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework.authentication.UserBasicAuthentication',
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ The default authentication policy may be set globally, using the `DEFAULT_AUTHEN
|
||||||
You can also set the authentication policy on a per-view basis, using the `APIView` class based views.
|
You can also set the authentication policy on a per-view basis, using the `APIView` class based views.
|
||||||
|
|
||||||
class ExampleView(APIView):
|
class ExampleView(APIView):
|
||||||
authentication_classes = (SessionAuthentication, UserBasicAuthentication)
|
authentication_classes = (SessionAuthentication, BasicAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
@ -51,7 +51,7 @@ You can also set the authentication policy on a per-view basis, using the `APIVi
|
||||||
Or, if you're using the `@api_view` decorator with function based views.
|
Or, if you're using the `@api_view` decorator with function based views.
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
@authentication_classes((SessionAuthentication, UserBasicAuthentication))
|
@authentication_classes((SessionAuthentication, BasicAuthentication))
|
||||||
@permissions_classes((IsAuthenticated,))
|
@permissions_classes((IsAuthenticated,))
|
||||||
def example_view(request, format=None):
|
def example_view(request, format=None):
|
||||||
content = {
|
content = {
|
||||||
|
|
|
@ -31,8 +31,8 @@ The default throttling policy may be set globally, using the `DEFAULT_THROTTLE_C
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.AnonThrottle',
|
'rest_framework.throttling.AnonRateThrottle',
|
||||||
'rest_framework.throttles.UserThrottle'
|
'rest_framework.throttling.UserRateThrottle'
|
||||||
),
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'anon': '100/day',
|
'anon': '100/day',
|
||||||
|
@ -136,7 +136,7 @@ For example, given the following views...
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.ScopedRateThrottle'
|
'rest_framework.throttling.ScopedRateThrottle'
|
||||||
),
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'contacts': '1000/day',
|
'contacts': '1000/day',
|
||||||
|
|
|
@ -211,9 +211,9 @@ class ModelField(WritableField):
|
||||||
def from_native(self, value):
|
def from_native(self, value):
|
||||||
try:
|
try:
|
||||||
rel = self.model_field.rel
|
rel = self.model_field.rel
|
||||||
|
return rel.to._meta.get_field(rel.field_name).to_python(value)
|
||||||
except:
|
except:
|
||||||
return self.model_field.to_python(value)
|
return self.model_field.to_python(value)
|
||||||
return rel.to._meta.get_field(rel.field_name).to_python(value)
|
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name):
|
||||||
value = self.model_field._get_val_from_obj(obj)
|
value = self.model_field._get_val_from_obj(obj)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user