Skip to content

Commit 6aef157

Browse files
committed
Merge remote-tracking branch 'tomchristie/master'
2 parents c774a4c + b8c9c80 commit 6aef157

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1369
-546
lines changed

docs/api-guide/fields.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Note that setting a `default` value implies that the field is not required. Incl
5757

5858
### `source`
5959

60-
The name of the attribute that will be used to populate the field. May be a method that only takes a `self` argument, such as `URLField('get_absolute_url')`, or may use dotted notation to traverse attributes, such as `EmailField(source='user.email')`.
60+
The name of the attribute that will be used to populate the field. May be a method that only takes a `self` argument, such as `URLField(source='get_absolute_url')`, or may use dotted notation to traverse attributes, such as `EmailField(source='user.email')`.
6161

6262
The value `source='*'` has a special meaning, and is used to indicate that the entire object should be passed through to the field. This can be useful for creating nested representations, or for fields which require access to the complete object in order to determine the output representation.
6363

@@ -85,9 +85,9 @@ A value that should be used for pre-populating the value of HTML form fields.
8585

8686
### `style`
8787

88-
A dictionary of key-value pairs that can be used to control how renderers should render the field. The API for this should still be considered experimental, and will be formalized with the 3.1 release.
88+
A dictionary of key-value pairs that can be used to control how renderers should render the field.
8989

90-
Two options are currently used in HTML form generation, `'input_type'` and `'base_template'`.
90+
Two examples here are `'input_type'` and `'base_template'`:
9191

9292
# Use <input type="password"> for the input.
9393
password = serializers.CharField(
@@ -100,7 +100,7 @@ Two options are currently used in HTML form generation, `'input_type'` and `'bas
100100
style = {'base_template': 'radio.html'}
101101
}
102102

103-
**Note**: The `style` argument replaces the old-style version 2.x `widget` keyword argument. Because REST framework 3 now uses templated HTML form generation, the `widget` option that was used to support Django built-in widgets can no longer be supported. Version 3.3 is planned to include public API support for customizing HTML form generation.
103+
For more details see the [HTML & Forms][html-and-forms] documentation.
104104

105105
---
106106

@@ -658,6 +658,7 @@ The [django-rest-framework-gis][django-rest-framework-gis] package provides geog
658658
The [django-rest-framework-hstore][django-rest-framework-hstore] package provides an `HStoreField` to support [django-hstore][django-hstore] `DictionaryField` model field.
659659

660660
[cite]: https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.cleaned_data
661+
[html-and-forms]: ../topics/html-and-forms.md
661662
[FILE_UPLOAD_HANDLERS]: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FILE_UPLOAD_HANDLERS
662663
[ecma262]: http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
663664
[strftime]: http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

docs/api-guide/filtering.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ We can override `.get_queryset()` to deal with URLs such as `http://example.com/
8383

8484
As well as being able to override the default queryset, REST framework also includes support for generic filtering backends that allow you to easily construct complex searches and filters.
8585

86+
Generic filters can also present themselves as HTML controls in the browsable API and admin API.
87+
88+
![Filter Example](../img/filter-controls.png)
89+
8690
## Setting filter backends
8791

8892
The default filter backends may be set globally, using the `DEFAULT_FILTER_BACKENDS` setting. For example.
@@ -95,9 +99,9 @@ You can also set the filter backends on a per-view, or per-viewset basis,
9599
using the `GenericAPIView` class based views.
96100

97101
from django.contrib.auth.models import User
98-
from myapp.serializers import UserSerializer
102+
from myapp.serializers import UserSerializer
99103
from rest_framework import filters
100-
from rest_framework import generics
104+
from rest_framework import generics
101105

102106
class UserListView(generics.ListAPIView):
103107
queryset = User.objects.all()
@@ -141,6 +145,13 @@ To use REST framework's `DjangoFilterBackend`, first install `django-filter`.
141145

142146
pip install django-filter
143147

148+
If you are using the browsable API or admin API you may also want to install `crispy-forms`, which will enhance the presentation of the filter forms in HTML views, by allowing them to render Bootstrap 3 HTML.
149+
150+
pip install django-crispy-forms
151+
152+
With crispy forms installed, the browsable API will present a filtering control for `DjangoFilterBackend`, like so:
153+
154+
![Django Filter](../../docs/img/django-filter.png)
144155

145156
#### Specifying filter fields
146157

@@ -237,6 +248,10 @@ For more details on using filter sets see the [django-filter documentation][djan
237248

238249
The `SearchFilter` class supports simple single query parameter based searching, and is based on the [Django admin's search functionality][search-django-admin].
239250

251+
When in use, the browsable API will include a `SearchFilter` control:
252+
253+
![Search Filter](../../docs/img/search-filter.png)
254+
240255
The `SearchFilter` class will only be applied if the view has a `search_fields` attribute set. The `search_fields` attribute should be a list of names of text type fields on the model, such as `CharField` or `TextField`.
241256

242257
class UserListView(generics.ListAPIView):
@@ -274,7 +289,11 @@ For more details, see the [Django documentation][search-django-admin].
274289

275290
## OrderingFilter
276291

277-
The `OrderingFilter` class supports simple query parameter controlled ordering of results. By default, the query parameter is named `'ordering'`, but this may by overridden with the `ORDERING_PARAM` setting.
292+
The `OrderingFilter` class supports simple query parameter controlled ordering of results.
293+
294+
![Ordering Filter](../../docs/img/ordering-filter.png)
295+
296+
By default, the query parameter is named `'ordering'`, but this may by overridden with the `ORDERING_PARAM` setting.
278297

279298
For example, to order users by username:
280299

@@ -389,6 +408,14 @@ For example, you might need to restrict users to only being able to see objects
389408

390409
We could achieve the same behavior by overriding `get_queryset()` on the views, but using a filter backend allows you to more easily add this restriction to multiple views, or to apply it across the entire API.
391410

411+
## Customizing the interface
412+
413+
Generic filters may also present an interface in the browsable API. To do so you should implement a `to_html()` method which returns a rendered HTML representation of the filter. This method should have the following signature:
414+
415+
`to_html(self, request, queryset, view)`
416+
417+
The method should return a rendered HTML string.
418+
392419
# Third party packages
393420

394421
The following third party packages provide additional filter implementations.

docs/api-guide/relations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Would serialize to a nested representation like this:
288288

289289
# Writable nested serializers
290290

291-
Be default nested serializers are read-only. If you want to to support write-operations to a nested serializer field you'll need to create either or both of the `create()` and/or `update()` methods, in order to explicitly specify how the child relationships should be saved.
291+
By default nested serializers are read-only. If you want to support write-operations to a nested serializer field you'll need to create `create()` and/or `update()` methods in order to explicitly specify how the child relationships should be saved.
292292

293293
class TrackSerializer(serializers.ModelSerializer):
294294
class Meta:

docs/api-guide/renderers.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,27 @@ Note that views that have nested or list serializers for their input won't work
197197

198198
## HTMLFormRenderer
199199

200-
Renders data returned by a serializer into an HTML form. The output of this renderer does not include the enclosing `<form>` tags or an submit actions, as you'll probably need those to include the desired method and URL. Also note that the `HTMLFormRenderer` does not yet support including field error messages.
200+
Renders data returned by a serializer into an HTML form. The output of this renderer does not include the enclosing `<form>` tags, a hidden CSRF input or any submit buttons.
201201

202-
**Note**: The `HTMLFormRenderer` class is intended for internal use with the browsable API and admin interface. It should not be considered a fully documented or stable API. The template used by the `HTMLFormRenderer` class, and the context submitted to it **may be subject to change**. If you need to use this renderer class it is advised that you either make a local copy of the class and templates, or follow the release note on REST framework upgrades closely.
202+
This renderer is not intended to be used directly, but can instead be used in templates by passing a serializer instance to the `render_form` template tag.
203+
204+
{% load rest_framework %}
205+
206+
<form action="/submit-report/" method="post">
207+
{% csrf_token %}
208+
{% render_form serializer %}
209+
<input type="submit" value="Save" />
210+
</form>
211+
212+
For more information see the [HTML & Forms][html-and-forms] documentation.
203213

204214
**.media_type**: `text/html`
205215

206216
**.format**: `'.form'`
207217

208218
**.charset**: `utf-8`
209219

210-
**.template**: `'rest_framework/form.html'`
220+
**.template**: `'rest_framework/horizontal/form.html'`
211221

212222
## MultiPartRenderer
213223

@@ -455,6 +465,7 @@ Comma-separated values are a plain-text tabular data format, that can be easily
455465

456466
[cite]: https://docs.djangoproject.com/en/dev/ref/template-response/#the-rendering-process
457467
[conneg]: content-negotiation.md
468+
[html-and-forms]: ../topics/html-and-forms.md
458469
[browser-accept-headers]: http://www.gethifi.com/blog/browser-rest-http-accept-headers
459470
[testing]: testing.md
460471
[HATEOAS]: http://timelessrepo.com/haters-gonna-hateoas

docs/api-guide/serializers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Similarly if a nested representation should be a list of items, you should pass
287287

288288
## Writable nested representations
289289

290-
When dealing with nested representations that support deserializing the data, an errors with nested objects will be nested under the field name of the nested object.
290+
When dealing with nested representations that support deserializing the data, any errors with nested objects will be nested under the field name of the nested object.
291291

292292
serializer = CommentSerializer(data={'user': {'email': 'foobar', 'username': 'doe'}, 'content': 'baz'})
293293
serializer.is_valid()
@@ -356,7 +356,7 @@ It is possible that a third party package, providing automatic support some kind
356356

357357
#### Handling saving related instances in model manager classes
358358

359-
An alternative to saving multiple related instances in the serializer is to write custom model manager classes handle creating the correct instances.
359+
An alternative to saving multiple related instances in the serializer is to write custom model manager classes that handle creating the correct instances.
360360

361361
For example, suppose we wanted to ensure that `User` instances and `Profile` instances are always created together as a pair. We might write a custom manager class that looks something like this:
362362

@@ -405,7 +405,7 @@ To serialize a queryset or list of objects instead of a single object instance,
405405

406406
#### Deserializing multiple objects
407407

408-
The default behavior for deserializing multiple objects is to support multiple object creation, but not support multiple object updates. For more information on how to support or customize either of these cases, see the [ListSerializer](#ListSerializer) documentation below.
408+
The default behavior for deserializing multiple objects is to support multiple object creation, but not support multiple object updates. For more information on how to support or customize either of these cases, see the [ListSerializer](#listserializer) documentation below.
409409

410410
## Including extra context
411411

@@ -478,7 +478,7 @@ For example:
478478
model = Account
479479
fields = '__all__'
480480

481-
You can set the `exclude` attribute of the to a list of fields to be excluded from the serializer.
481+
You can set the `exclude` attribute to a list of fields to be excluded from the serializer.
482482

483483
For example:
484484

@@ -551,7 +551,7 @@ Please review the [Validators Documentation](/api-guide/validators/) for details
551551

552552
## Additional keyword arguments
553553

554-
There is also a shortcut allowing you to specify arbitrary additional keyword arguments on fields, using the `extra_kwargs` option. Similarly to `read_only_fields` this means you do not need to explicitly declare the field on the serializer.
554+
There is also a shortcut allowing you to specify arbitrary additional keyword arguments on fields, using the `extra_kwargs` option. As in the case of `read_only_fields`, this means you do not need to explicitly declare the field on the serializer.
555555

556556
This option is a dictionary, mapping field names to a dictionary of keyword arguments. For example:
557557

@@ -832,7 +832,7 @@ This class implements the same basic API as the `Serializer` class:
832832
* `.data` - Returns the outgoing primitive representation.
833833
* `.is_valid()` - Deserializes and validates incoming data.
834834
* `.validated_data` - Returns the validated incoming data.
835-
* `.errors` - Returns an errors during validation.
835+
* `.errors` - Returns any errors during validation.
836836
* `.save()` - Persists the validated data into an object instance.
837837

838838
There are four methods that can be overridden, depending on what functionality you want the serializer class to support:

docs/api-guide/versioning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The following settings keys are also used to control versioning:
7272

7373
* `DEFAULT_VERSION`. The value that should be used for `request.version` when no versioning information is present. Defaults to `None`.
7474
* `ALLOWED_VERSIONS`. If set, this value will restrict the set of versions that may be returned by the versioning scheme, and will raise an error if the provided version if not in this set. Note that the value used for the `DEFAULT_VERSION` setting is always considered to be part of the `ALLOWED_VERSIONS` set. Defaults to `None`.
75-
* `VERSION_PARAMETER`. The string that should used for any versioning parameters, such as in the media type or URL query parameters. Defaults to `'version'`.
75+
* `VERSION_PARAM`. The string that should used for any versioning parameters, such as in the media type or URL query parameters. Defaults to `'version'`.
7676

7777
You can also set your versioning class plus those three values on a per-view or a per-viewset basis by defining your own versioning scheme and using the `default_version`, `allowed_versions` and `version_param` class variables. For example, if you want to use `URLPathVersioning`:
7878

docs/img/django-filter.png

13.4 KB
Loading

docs/img/filter-controls.png

46.8 KB
Loading

docs/img/horizontal.png

11.4 KB
Loading

docs/img/inline.png

8.1 KB
Loading

docs/img/ordering-filter.png

17.8 KB
Loading

docs/img/search-filter.png

8.92 KB
Loading

docs/img/vertical.png

11.7 KB
Loading

docs/index.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
---
1414

15-
**Note**: This is the documentation for the **version 3.2** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
16-
17-
For more details see the 3.2 [announcement][3.2-announcement] and [release notes][release-notes].
15+
**Note**: This is the documentation for the **version 3** of REST framework. Documentation for [version 2](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
1816

1917
---
2018

@@ -31,7 +29,7 @@ For more details see the 3.2 [announcement][3.2-announcement] and [release notes
3129
<img alt="Django REST Framework" title="Logo by Jake 'Sid' Smith" src="img/logo.png" width="600px" style="display: block; margin: 0 auto 0 auto">
3230
</p>
3331

34-
Django REST framework is a powerful and flexible toolkit that makes it easy to build Web APIs.
32+
Django REST framework is a powerful and flexible toolkit for building Web APIs.
3533

3634
Some reasons you might want to use REST framework:
3735

@@ -52,13 +50,14 @@ Some reasons you might want to use REST framework:
5250

5351
REST framework requires the following:
5452

55-
* Python (2.6.5+, 2.7, 3.2, 3.3, 3.4, 3.5)
53+
* Python (2.7, 3.2, 3.3, 3.4, 3.5)
5654
* Django (1.7+, 1.8, 1.9)
5755

5856
The following packages are optional:
5957

6058
* [Markdown][markdown] (2.1.0+) - Markdown support for the browsable API.
6159
* [django-filter][django-filter] (0.9.2+) - Filtering support.
60+
* [django-crispy-forms][django-crispy-forms] - Improved HTML display for filtering.
6261
* [django-guardian][django-guardian] (1.1.1+) - Object level permissions support.
6362

6463
## Installation
@@ -191,7 +190,9 @@ The API guide is your complete reference manual to all the functionality provide
191190
General guides to using REST framework.
192191

193192
* [Documenting your API][documenting-your-api]
193+
* [Internationalization][internationalization]
194194
* [AJAX, CSRF & CORS][ajax-csrf-cors]
195+
* [HTML & Forms][html-and-forms]
195196
* [Browser enhancements][browser-enhancements]
196197
* [The Browsable API][browsableapi]
197198
* [REST, Hypermedia & HATEOAS][rest-hypermedia-hateoas]
@@ -201,7 +202,9 @@ General guides to using REST framework.
201202
* [3.0 Announcement][3.0-announcement]
202203
* [3.1 Announcement][3.1-announcement]
203204
* [3.2 Announcement][3.2-announcement]
205+
* [3.3 Announcement][3.3-announcement]
204206
* [Kickstarter Announcement][kickstarter-announcement]
207+
* [Funding][funding]
205208
* [Release Notes][release-notes]
206209

207210
## Development
@@ -303,8 +306,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303306
[settings]: api-guide/settings.md
304307

305308
[documenting-your-api]: topics/documenting-your-api.md
306-
[internationalization]: topics/documenting-your-api.md
309+
[internationalization]: topics/internationalization.md
307310
[ajax-csrf-cors]: topics/ajax-csrf-cors.md
311+
[html-and-forms]: topics/html-and-forms.md
308312
[browser-enhancements]: topics/browser-enhancements.md
309313
[browsableapi]: topics/browsable-api.md
310314
[rest-hypermedia-hateoas]: topics/rest-hypermedia-hateoas.md
@@ -314,7 +318,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
314318
[3.0-announcement]: topics/3.0-announcement.md
315319
[3.1-announcement]: topics/3.1-announcement.md
316320
[3.2-announcement]: topics/3.2-announcement.md
321+
[3.3-announcement]: topics/3.3-announcement.md
317322
[kickstarter-announcement]: topics/kickstarter-announcement.md
323+
[funding]: topics/funding.md
318324
[release-notes]: topics/release-notes.md
319325

320326
[tox]: http://testrun.org/tox/latest/

0 commit comments

Comments
 (0)