diff options
| author | Tom Christie | 2015-01-30 14:00:25 +0000 | 
|---|---|---|
| committer | Tom Christie | 2015-01-30 14:00:25 +0000 | 
| commit | 4ee4b4f2dc3cffd8246772bdf829a2a720493377 (patch) | |
| tree | 95b514483e901c10bdeee0d66e60430002d5101a /docs/api-guide | |
| parent | 8f33e39f62c59d06783dd3e6e7cf8d464ff08c5f (diff) | |
| parent | 7cf9dea7f905ea6869148a68b4fa96cad0a347e8 (diff) | |
| download | django-rest-framework-4ee4b4f2dc3cffd8246772bdf829a2a720493377.tar.bz2 | |
Merge master
Diffstat (limited to 'docs/api-guide')
| -rw-r--r-- | docs/api-guide/fields.md | 29 | ||||
| -rw-r--r-- | docs/api-guide/filtering.md | 4 | ||||
| -rwxr-xr-x | docs/api-guide/generic-views.md | 8 | ||||
| -rw-r--r-- | docs/api-guide/parsers.md | 2 | ||||
| -rw-r--r-- | docs/api-guide/routers.md | 12 | ||||
| -rw-r--r-- | docs/api-guide/viewsets.md | 2 | 
6 files changed, 38 insertions, 19 deletions
| diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index b3d274dd..10291c12 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -182,6 +182,12 @@ Corresponds to `django.db.models.fields.URLField`.  Uses Django's `django.core.v  **Signature:** `URLField(max_length=200, min_length=None, allow_blank=False)` +## UUIDField + +A field that ensures the input is a valid UUID string. The `to_internal_value` method will return a `uuid.UUID` instance. On output the field will return a string in the canonical hyphenated format, for example: + +    "de305d54-75b4-431b-adb2-eb6b9e546013" +  ---  # Numeric fields @@ -320,7 +326,7 @@ Both the `allow_blank` and `allow_null` are valid options on `ChoiceField`, alth  ## MultipleChoiceField -A field that can accept a set of zero, one or many values, chosen from a limited set of choices. Takes a single mandatory argument. `to_internal_representation` returns a `set` containing the selected values. +A field that can accept a set of zero, one or many values, chosen from a limited set of choices. Takes a single mandatory argument. `to_internal_value` returns a `set` containing the selected values.  **Signature:** `MultipleChoiceField(choices)` @@ -374,7 +380,7 @@ A field class that validates a list of objects.  **Signature**: `ListField(child)` -- `child` - A field instance that should be used for validating the objects in the list. +- `child` - A field instance that should be used for validating the objects in the list. If this argument is not provided then objects in the list will not be validated.  For example, to validate a list of integers you might use something like the following: @@ -389,6 +395,23 @@ The `ListField` class also supports a declarative style that allows you to write  We can now reuse our custom `StringListField` class throughout our application, without having to provide a `child` argument to it. +## DictField + +A field class that validates a dictionary of objects. The keys in `DictField` are always assumed to be string values. + +**Signature**: `DictField(child)` + +- `child` - A field instance that should be used for validating the values in the dictionary. If this argument is not provided then values in the mapping will not be validated. + +For example, to create a field that validates a mapping of strings to strings, you would write something like this: + +    document = DictField(child=CharField()) + +You can also use the declarative style, as with `ListField`. For example: + +    class DocumentField(DictField): +        child = CharField() +  ---  # Miscellaneous fields @@ -438,7 +461,7 @@ This is a read-only field. It gets its value by calling a method on the serializ  **Signature**: `SerializerMethodField(method_name=None)` -- `method-name` - The name of the method on the serializer to be called. If not included this defaults to `get_<field_name>`. +- `method_name` - The name of the method on the serializer to be called. If not included this defaults to `get_<field_name>`.  The serializer method referred to by the `method_name` argument should accept a single argument (in addition to `self`), which is the object being serialized. It should return whatever you want to be included in the serialized representation of the object. For example: diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index e00560c7..b16b6be5 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -398,8 +398,8 @@ The [django-rest-framework-filters package][django-rest-framework-filters] works  [cite]: https://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-objects-with-filters  [django-filter]: https://github.com/alex/django-filter  [django-filter-docs]: https://django-filter.readthedocs.org/en/latest/index.html -[guardian]: http://pythonhosted.org/django-guardian/ -[view-permissions]: http://pythonhosted.org/django-guardian/userguide/assign.html +[guardian]: https://django-guardian.readthedocs.org/ +[view-permissions]: https://django-guardian.readthedocs.org/en/latest/userguide/assign.html  [view-permissions-blogpost]: http://blog.nyaruka.com/adding-a-view-permission-to-django-models  [nullbooleanselect]: https://github.com/django/django/blob/master/django/forms/widgets.py  [search-django-admin]: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index 6374e305..61c8e8d8 100755 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -93,17 +93,13 @@ The following attributes are used to control pagination when used with list view  * `filter_backends` - A list of filter backend classes that should be used for filtering the queryset.  Defaults to the same value as the `DEFAULT_FILTER_BACKENDS` setting. -**Deprecated attributes**: - -* `model` - This shortcut may be used instead of setting either (or both) of the `queryset`/`serializer_class` attributes. The explicit style is preferred over the `.model` shortcut, and usage of this attribute is now deprecated. -  ### Methods  **Base methods**:  #### `get_queryset(self)` -Returns the queryset that should be used for list views, and that should be used as the base for lookups in detail views.  Defaults to returning the queryset specified by the `queryset` attribute, or the default queryset for the model if the `model` shortcut is being used. +Returns the queryset that should be used for list views, and that should be used as the base for lookups in detail views.  Defaults to returning the queryset specified by the `queryset` attribute.  This method should always be used rather than accessing `self.queryset` directly, as `self.queryset` gets evaluated only once, and those results are cached for all subsequent requests. @@ -153,7 +149,7 @@ For example:  #### `get_serializer_class(self)` -Returns the class that should be used for the serializer.  Defaults to returning the `serializer_class` attribute, or dynamically generating a serializer class if the `model` shortcut is being used. +Returns the class that should be used for the serializer.  Defaults to returning the `serializer_class` attribute.  May be overridden to provide dynamic behavior, such as using different serializers for read and write operations, or providing different serializers to different types of users. diff --git a/docs/api-guide/parsers.md b/docs/api-guide/parsers.md index b68b33be..c242f878 100644 --- a/docs/api-guide/parsers.md +++ b/docs/api-guide/parsers.md @@ -108,7 +108,7 @@ If the view used with `FileUploadParser` is called with a `filename` URL keyword          def put(self, request, filename, format=None):              file_obj = request.data['file']              # ... -            # do some staff with uploaded file +            # do some stuff with uploaded file              # ...              return Response(status=204) diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md index 9c9bfb50..592f7d66 100644 --- a/docs/api-guide/routers.md +++ b/docs/api-guide/routers.md @@ -28,7 +28,7 @@ There are two mandatory arguments to the `register()` method:  Optionally, you may also specify an additional argument: -* `base_name` - The base to use for the URL names that are created.  If unset the basename will be automatically generated based on the `model` or `queryset` attribute on the viewset, if it has one.  Note that if the viewset does not include a `model` or `queryset` attribute then you must set `base_name` when registering the viewset. +* `base_name` - The base to use for the URL names that are created.  If unset the basename will be automatically generated based on the `queryset` attribute of the viewset, if it has one.  Note that if the viewset does not include a `queryset` attribute then you must set `base_name` when registering the viewset.  The example above would generate the following URL patterns: @@ -60,7 +60,7 @@ For example, you can append `router.urls` to a list of existing views…      router.register(r'accounts', AccountViewSet)      urlpatterns = [ -        url(r'^forgot-password/$', ForgotPasswordFormView.as_view(), +        url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),      ]      urlpatterns += router.urls @@ -68,15 +68,15 @@ For example, you can append `router.urls` to a list of existing views…  Alternatively you can use Django's `include` function, like so…      urlpatterns = [ -        url(r'^forgot-password/$', ForgotPasswordFormView.as_view(), -        url(r'^', include(router.urls)) +        url(r'^forgot-password/$', ForgotPasswordFormView.as_view()), +        url(r'^', include(router.urls)),      ]  Router URL patterns can also be namespaces.      urlpatterns = [ -        url(r'^forgot-password/$', ForgotPasswordFormView.as_view(), -        url(r'^api/', include(router.urls, namespace='api')) +        url(r'^forgot-password/$', ForgotPasswordFormView.as_view()), +        url(r'^api/', include(router.urls, namespace='api')),      ]  If using namespacing with hyperlinked serializers you'll also need to ensure that any `view_name` parameters on the serializers correctly reflect the namespace. In the example above you'd need to include a parameter such as `view_name='api:user-detail'` for serializer fields hyperlinked to the user detail view. diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 3e37cef8..b09dfc9e 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -146,7 +146,7 @@ The decorators can additionally take extra arguments that will be set for the ro          def set_password(self, request, pk=None):             ... -Theses decorators will route `GET` requests by default, but may also accept other HTTP methods, by using the `methods` argument.  For example: +These decorators will route `GET` requests by default, but may also accept other HTTP methods, by using the `methods` argument.  For example:          @detail_route(methods=['post', 'delete'])          def unset_password(self, request, pk=None): | 
