You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
12
12
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
13
13
14
-
For more details see the [3.0 release notes](3.0-announcement).
14
+
For more details see the [3.0 release notes][3.0-announcement].
Copy file name to clipboardExpand all lines: docs/topics/3.0-announcement.md
+36-6Lines changed: 36 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,11 @@ This release is incremental in nature. There *are* some breaking API changes, an
6
6
7
7
The difference in quality of the REST framework API and implementation should make writing, maintaining and debugging your application far easier.
8
8
9
-
3.0 is the first of three releases that have been funded by our recent [Kickstarter campaign](kickstarter.com/projects/tomchristie/django-rest-framework-3).
9
+
3.0 is the first of three releases that have been funded by our recent [Kickstarter campaign][kickstarter].
10
10
11
-
As ever, a huge thank you to our many [wonderful sponsors](sponsors). If you're looking for a Django gig, and want to work with smart community-minded folks, you should probably check out that list and see who's hiring.
11
+
As ever, a huge thank you to our many [wonderful sponsors][sponsors]. If you're looking for a Django gig, and want to work with smart community-minded folks, you should probably check out that list and see who's hiring.
12
+
13
+
---
12
14
13
15
## New features
14
16
@@ -51,6 +53,8 @@ Instead of passing the files argument separately:
51
53
52
54
The usage of `request.QUERY_PARAMS` is now pending deprecation in favor of the lowercased `request.query_params`.
53
55
56
+
---
57
+
54
58
## Serializers
55
59
56
60
#### Single-step object creation.
@@ -149,7 +153,7 @@ Previously `serializers.ValidationError` error was simply a synonym for `django.
149
153
150
154
The reason behind this is that Django's `ValidationError` class is intended for use with HTML forms and its API makes using it slightly awkward with nested validation errors that can occur in serializers.
151
155
152
-
For most users this change shouldn't require any updates to your codebase, but it is worth ensuring that whenever raising validation errors you are always using the `serializers.ValidationError` exception class, and not Django's built-in exception.
156
+
For most users this change shouldn't require any updates to your codebase, but it is worth ensuring that whenever raising validation errors you should prefer using the `serializers.ValidationError` exception class, and not Django's built-in exception.
153
157
154
158
We strongly recommend that you use the namespaced import style of `import serializers` and not `from serializers import ValidationError` in order to avoid any potential confusion.
155
159
@@ -218,7 +222,18 @@ If you absolutely need to preserve `transform_<field_name>` behavior, for exampl
218
222
219
223
This change also means that we no longer use the `.full_clean()` method on model instances, but instead perform all validation explicitly on the serializer. This gives a cleaner separation, and ensures that there's no automatic validation behavior on `ModelSerializer` classes that can't also be easily replicated on regular `Serializer` classes.
220
224
221
-
It's important to note that this change also means that the model `.clean()` method will not be called as part of serializer validation, as it would be if using a `ModelForm`. Use the serializer `.validate()` method to perform a final validation step on incoming data where required.
225
+
For the most part this change should be transparent. Field validation and uniqueness checks will still be run as normal, but the implementation is a little different.
226
+
227
+
The one difference that you do need to note is that the `.clean()` method will not be called as part of serializer validation, as it would be if using a `ModelForm`. Use the serializer `.validate()` method to perform a final validation step on incoming data where required.
228
+
229
+
There may be some cases where you really do need to keep validation logic in the model `.clean()` method, and cannot instead separate it into the serializer `.validate()`. You can do so by explicitly instantiating a model instance in the `.validate()` method.
230
+
231
+
def validate(self, attrs):
232
+
instance = ExampleModel(**attrs)
233
+
instance.clean()
234
+
return attrs
235
+
236
+
Again, you really should look at properly separating the validation logic out of the model method if possible, but the above might be useful in some backwards compatibility cases, or for an easy migration path.
222
237
223
238
#### Writable nested serialization.
224
239
@@ -524,6 +539,8 @@ The following class is an example of a generic serializer that can handle coerci
524
539
# Force anything else to its string representation.
525
540
output[attribute_name] = str(attribute)
526
541
542
+
---
543
+
527
544
## Serializer fields
528
545
529
546
#### The `Field` and `ReadOnly` field classes.
@@ -721,6 +738,8 @@ REST framework also now includes explicit validator classes for validating the `
721
738
722
739
These classes are documented in the [Validators](../api-guide/validators.md) section of the documentation.
723
740
741
+
---
742
+
724
743
## Generic views
725
744
726
745
#### Simplification of view logic.
@@ -769,12 +788,16 @@ The generic views now raise `ValidationFailed` exception for invalid data. This
769
788
770
789
This change means that you can now easily customize the style of error responses across your entire API, without having to modify any of the generic views.
771
790
791
+
---
792
+
772
793
## The metadata API
773
794
774
795
Behavior for dealing with `OPTIONS` requests was previously built directly into the class based views. This has now been properly separated out into a Metadata API that allows the same pluggable style as other API policies in REST framework.
775
796
776
797
This makes it far easier to use a different style for `OPTIONS` responses throughout your API, and makes it possible to create third-party metadata policies.
777
798
799
+
---
800
+
778
801
## Serializers as HTML forms
779
802
780
803
REST framework 3.0 includes templated HTML form rendering for serializers.
@@ -806,6 +829,8 @@ Similarly, to use a radio button control instead of the default `select` control
806
829
807
830
This API should be considered provisional, and there may be minor alterations with the incoming 3.1 release.
808
831
832
+
---
833
+
809
834
## API style
810
835
811
836
There are some improvements in the default style we use in our API responses.
@@ -899,12 +924,16 @@ Or modify it on an individual serializer field, using the `coerce_to_string` key
899
924
900
925
The default JSON renderer will return float objects for un-coerced `Decimal` instances. This allows you to easily switch between string or float representations for decimals depending on your API design needs.
901
926
902
-
## Miscellaneous notes.
927
+
---
928
+
929
+
## Miscellaneous notes
903
930
904
931
* The serializer `ChoiceField` does not currently display nested choices, as was the case in 2.4. This will be address as part of 3.1.
905
932
* Due to the new templated form rendering, the 'widget' option is no longer valid. This means there's no easy way of using third party "autocomplete" widgets for rendering select inputs that contain a large number of choices. You'll either need to use a regular select or a plain text input. We may consider addressing this in 3.1 or 3.2 if there's sufficient demand.
906
933
907
-
## What's coming next.
934
+
---
935
+
936
+
## What's coming next
908
937
909
938
3.0 is an incremental release, and there are several upcoming features that will build on the baseline improvements that it makes.
910
939
@@ -919,5 +948,6 @@ The 3.2 release is planned to introduce an alternative admin-style interface to
919
948
920
949
You can follow development on the GitHub site, where we use [milestones to indicate planning timescales](https://github.com/tomchristie/django-rest-framework/milestones).
0 commit comments