mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-04 15:34:05 +03:00
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework
This commit is contained in:
commit
656a13616d
|
@ -87,7 +87,7 @@ The default filter backends may be set globally, using the `DEFAULT_FILTER_BACKE
|
||||||
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
|
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
|
||||||
}
|
}
|
||||||
|
|
||||||
You can also set the authentication policy on a per-view, or per-viewset basis,
|
You can also set the filter backends on a per-view, or per-viewset basis,
|
||||||
using the `GenericAPIView` class based views.
|
using the `GenericAPIView` class based views.
|
||||||
|
|
||||||
class UserListView(generics.ListAPIView):
|
class UserListView(generics.ListAPIView):
|
||||||
|
@ -216,7 +216,7 @@ For more details, see the [Django documentation][search-django-admin].
|
||||||
|
|
||||||
## OrderingFilter
|
## OrderingFilter
|
||||||
|
|
||||||
The `OrderingFilter` class supports simple query parameter controlled ordering of results. To specify the result order, set a query parameter named `'order'` to the required field name. For example:
|
The `OrderingFilter` class supports simple query parameter controlled ordering of results. To specify the result order, set a query parameter named `'ordering'` to the required field name. For example:
|
||||||
|
|
||||||
http://example.com/api/users?ordering=username
|
http://example.com/api/users?ordering=username
|
||||||
|
|
||||||
|
|
|
@ -389,10 +389,24 @@ class URLField(CharField):
|
||||||
|
|
||||||
class SlugField(CharField):
|
class SlugField(CharField):
|
||||||
type_name = 'SlugField'
|
type_name = 'SlugField'
|
||||||
|
form_field_class = forms.SlugField
|
||||||
|
|
||||||
|
default_error_messages = {
|
||||||
|
'invalid': _("Enter a valid 'slug' consisting of letters, numbers,"
|
||||||
|
" underscores or hyphens."),
|
||||||
|
}
|
||||||
|
default_validators = [validators.validate_slug]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(SlugField, self).__init__(*args, **kwargs)
|
super(SlugField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
result = copy.copy(self)
|
||||||
|
memo[id(self)] = result
|
||||||
|
#result.widget = copy.deepcopy(self.widget, memo)
|
||||||
|
result.validators = self.validators[:]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class ChoiceField(WritableField):
|
class ChoiceField(WritableField):
|
||||||
type_name = 'ChoiceField'
|
type_name = 'ChoiceField'
|
||||||
|
|
|
@ -769,6 +769,21 @@ class SlugFieldTests(TestCase):
|
||||||
self.assertEqual(serializer.is_valid(), True)
|
self.assertEqual(serializer.is_valid(), True)
|
||||||
self.assertEqual(getattr(serializer.fields['slug_field'], 'max_length'), 20)
|
self.assertEqual(getattr(serializer.fields['slug_field'], 'max_length'), 20)
|
||||||
|
|
||||||
|
def test_invalid_slug(self):
|
||||||
|
"""
|
||||||
|
Make sure an invalid slug raises ValidationError
|
||||||
|
"""
|
||||||
|
class SlugFieldSerializer(serializers.ModelSerializer):
|
||||||
|
slug_field = serializers.SlugField(source='slug_field', max_length=20, required=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = self.SlugFieldModel
|
||||||
|
|
||||||
|
s = SlugFieldSerializer(data={'slug_field': 'a b'})
|
||||||
|
|
||||||
|
self.assertEqual(s.is_valid(), False)
|
||||||
|
self.assertEqual(s.errors, {'slug_field': ["Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."]})
|
||||||
|
|
||||||
|
|
||||||
class URLFieldTests(TestCase):
|
class URLFieldTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user