Skip to content

Commit 071c064

Browse files
committed
Fill in TODOs for 3.0 beta release notes
1 parent 6a2023a commit 071c064

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

docs/topics/3.0-announcement.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Notable features of this new release include:
3636
* A more compact JSON output with unicode style encoding turned on by default.
3737
* Templated based HTML form rendering for serializers. This will be finalized as public API in the upcoming 3.1 release.
3838

39-
Significant new functionality continues to be planned for the 3.1 and 3.2 releases. These releases will present simple upgrades, without the same level of fundamental API changes necessary for the 3.0 release.
39+
Significant new functionality continues to be planned for the 3.1 and 3.2 releases. These releases will correspond to the two [Kickstarter stretch goals](https://www.kickstarter.com/projects/tomchristie/django-rest-framework-3) - "Feature improvements" and "Admin interface". Further 3.x releases will present simple upgrades, without the same level of fundamental API changes necessary for the 3.0 release.
4040

4141
Below is an in-depth guide to the API changes and migration notes for 3.0.
4242

@@ -145,6 +145,16 @@ The corresponding code would now look like this:
145145
logging.info('Creating ticket "%s"' % name)
146146
serializer.save(user=request.user) # Include the user when saving.
147147

148+
#### Using `.is_valid(raise_exception=True)`
149+
150+
The `.is_valid()` method now takes an optional boolean flag, `raise_exception`.
151+
152+
Calling `.is_valid(raise_exception=True)` will cause a `ValidationError` to be raised if the serializer data contains validation errors. This error will be handled by REST framework's default exception handler, allowing you to remove error response handling from your view code.
153+
154+
The handling and formatting of error responses may be altered globally by using the `EXCEPTION_HANDLER` settings key.
155+
156+
This change also means it's now possible to alter the style of error responses used by the built-in generic views, without having to include mixin classes or other overrides.
157+
148158
#### Using `serializers.ValidationError`.
149159

150160
Previously `serializers.ValidationError` error was simply a synonym for `django.core.exceptions.ValidationError`. This has now been altered so that it inherits from the standard `APIException` base class.
@@ -356,6 +366,8 @@ The `ListSerializer` class has now been added, and allows you to create base ser
356366

357367
You can also still use the `many=True` argument to serializer classes. It's worth noting that `many=True` argument transparently creates a `ListSerializer` instance, allowing the validation logic for list and non-list data to be cleanly separated in the REST framework codebase.
358368

369+
You will typically want to *continue to use the existing `many=True` flag* rather than declaring `ListSerializer` classes explicitly, but declaring the classes explicitly can be useful if you need to write custom `create` or `update` methods for bulk updates, or provide for other custom behavior.
370+
359371
See also the new `ListField` class, which validates input in the same way, but does not include the serializer interfaces of `.is_valid()`, `.data`, `.save()` and so on.
360372

361373
#### The `BaseSerializer` class.
@@ -673,7 +685,9 @@ The `UniqueTogetherValidator` should be applied to a serializer, and takes a `qu
673685

674686
#### The `UniqueForDateValidator` classes.
675687

676-
**TODO: Needs documenting.**
688+
REST framework also now includes explicit validator classes for validating the `unique_for_date`, `unique_for_month`, and `unique_for_year` model field constraints. These are used internally instead of calling into `Model.full_clean()`.
689+
690+
These classes are documented in the [Validators](../api-guide/validators.md) section of the documentation.
677691

678692
## Generic views
679693

@@ -731,7 +745,34 @@ This makes it far easier to use a different style for `OPTIONS` responses throug
731745

732746
## Serializers as HTML forms
733747

734-
**TODO: Document this.**
748+
REST framework 3.0 includes templated HTML form rendering for serializers.
749+
750+
This API should not yet be considered finalized, and will only be promoted to public API for the 3.1 release.
751+
752+
Significant changes that you do need to be aware of include:
753+
754+
* Nested HTML forms are now supported, for example, a `UserSerializer` with a nested `ProfileSerializer` will now render a nested `fieldset` when used in the browsable API.
755+
* Nested lists of HTML forms are not yet supported, but are planned for 3.1.
756+
* Because we now use templated HTML form generation, **the `widget` option is no longer available for serializer fields**. You can instead control the template that is used for a given field, by using the `style` dictionary.
757+
758+
#### The `style` keyword argument for serializer fields.
759+
760+
The `style` keyword argument can be used to pass through additional information from a serializer field, to the renderer class. In particular, the `HTMLFormRenderer` uses the `base_template` key to determine which template to render the field with.
761+
762+
For example, to use a `textarea` control instead of the default `input` control, you would use the following…
763+
764+
additional_notes = serializers.CharField(
765+
style={'base_template': 'text_area.html'}
766+
)
767+
768+
Similarly, to use a radio button control instead of the default `select` control, you would use the following…
769+
770+
color_channel = serializers.ChoiceField(
771+
choices=['red', 'blue', 'green'],
772+
style={'base_template': 'radio.html'}
773+
)
774+
775+
This API should be considered provisional, and there may be minor alterations with the incoming 3.1 release.
735776

736777
## API style
737778

0 commit comments

Comments
 (0)