From 1d65378886990a1dc5c36403d454ce251fbda457 Mon Sep 17 00:00:00 2001
From: Tom Christie Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. Each field in a Form class is responsible not only for validating data, but also for "cleaning" it — normalizing it to a consistent format. Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. Django’s generic views... were developed as a shortcut for common usage patterns... They take certain common idioms and patterns found in view development and abstract them so that you can quickly write common views of data without having to repeat yourself. Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. [The To enable the To enable the On The To set these attributes you should override the Optionally, you may also set a Optionally, you may also set a On The To set these attributes you should override the Proper use of cursor based pagination a little attention to detail. You'll need to think about what ordering you want the scheme to be applied against. The default is to order by Proper use of cursor based pagination requires a little attention to detail. You'll need to think about what ordering you want the scheme to be applied against. The default is to order by You can modify the ordering by overriding the Proper usage of cursor pagination should have an ordering field that satisfies the following: Using an ordering field that does not satisfy these constraints will generally still work, but you'll be loosing some of the benefits of cursor pagination. For more technical details on the implementation we use for cursor pagination, the "Building cursors for the Disqus API" blog post gives a good overview of the basic approach. To enable the To enable the On Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. Bad programmers worry about the code.
Good programmers worry about data structures and their relationships. Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. If you're doing REST-based web service stuff ... you should ignore request.POST. — Malcom Tredinnick, Django developers group Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. Expanding the usefulness of the serializers is something that we would
like to address. However, it's not a trivial problem, and it
diff --git a/api-guide/validators/index.html b/api-guide/validators/index.html
index 395fd9de1..d97fc213e 100644
--- a/api-guide/validators/index.html
+++ b/api-guide/validators/index.html
@@ -424,10 +424,7 @@
- Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available. Validators can be useful for re-using validation logic between different types of fields. As an example of how REST framework uses explicit validation, we'll take a simple model class that has a field with a uniqueness constraint. If we open up the Django shell using If we open up the Django shell using
-
-Serializer fields
+ Serializer fields
-
-Generic views
+ Generic views
-
-Metadata
+ Metadata
OPTIONS
] method allows a client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.Setup
-PageNumberPagination
style globally, use the following configuration, modifying the DEFAULT_PAGE_SIZE
as desired:PageNumberPagination
style globally, use the following configuration, modifying the PAGE_SIZE
as desired:REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
- 'DEFAULT_PAGE_SIZE': 100
+ 'PAGE_SIZE': 100
}
GenericAPIView
subclasses you may also set the pagination_class
attribute to select PageNumberPagination
on a per-view basis.PageNumberPagination
class includes a number of attributes that may be overridden to modify the pagination style.PageNumberPagination
class, and then enable your custom pagination class as above.
-
page_size
- A numeric value indicating the page size. If set, this overrides the DEFAULT_PAGE_SIZE
setting. Defaults to the same value as the DEFAULT_PAGE_SIZE
settings key.page_size
- A numeric value indicating the page size. If set, this overrides the PAGE_SIZE
setting. Defaults to the same value as the PAGE_SIZE
settings key.page_query_param
- A string value indicating the name of the query parameter to use for the pagination control.page_size_query_param
- If set, this is a string value indicating the name of a query parameter that allows the client to set the page size on a per-request basis. Defaults to None
, indicating that the client may not control the requested page size.max_page_size
- If set, this is a numeric value indicating the maximum allowable requested page size. This attribute is only valid if page_size_query_param
is also set.DEFAULT_PAGE_SIZE
key. If the DEFAULT_PAGE_SIZE
parameter is also used then the limit
query parameter will be optional, and may be omitted by the client.PAGE_SIZE
key. If the PAGE_SIZE
parameter is also used then the limit
query parameter will be optional, and may be omitted by the client.GenericAPIView
subclasses you may also set the pagination_class
attribute to select LimitOffsetPagination
on a per-view basis.Configuration
LimitOffsetPagination
class includes a number of attributes that may be overridden to modify the pagination style.LimitOffsetPagination
class, and then enable your custom pagination class as above.
-
default_limit
- A numeric value indicating the limit to use if one is not provided by the client in a query parameter. Defaults to the same value as the DEFAULT_PAGE_SIZE
settings key.default_limit
- A numeric value indicating the limit to use if one is not provided by the client in a query parameter. Defaults to the same value as the PAGE_SIZE
settings key.limit_query_param
- A string value indicating the name of the "limit" query parameter. Defaults to 'limit'
.offset_query_param
- A string value indicating the name of the "offset" query parameter. Defaults to 'offset'
.max_limit
- If set this is a numeric value indicating the maximum allowable limit that may be requested by the client. Defaults to None
.Details and limitations
-"-created"
. This assumes that there must be a 'created' timestamp field on the model instances, and will present a "timeline" style paginated view, with the most recently added items first."-created"
. This assumes that there must be a 'created' timestamp field on the model instances, and will present a "timeline" style paginated view, with the most recently added items first.'ordering'
attribute on the pagination class, or by using the OrderingFilter
filter class together with CursorPagination
. When used with OrderingFilter
you should strongly consider restricting the fields that the user may order by.
@@ -578,10 +578,10 @@ class StandardResultsSetPagination(PageNumberPagination):
Setup
-CursorPagination
style globally, use the following configuration, modifying the DEFAULT_PAGE_SIZE
as desired:CursorPagination
style globally, use the following configuration, modifying the PAGE_SIZE
as desired:REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.CursorPagination',
- 'DEFAULT_PAGE_SIZE': 100
+ 'PAGE_SIZE': 100
}
GenericAPIView
subclasses you may also set the pagination_class
attribute to select CursorPagination
on a per-view basis.
-
-Serializer relations
+ Serializer relations
-
-Requests
+ Requests
-
-Serializers
+ Serializers
-
-Validators
+ Validators
Example
@@ -455,7 +452,7 @@
class Meta:
model = CustomerReportRecord
-class CustomerReportRecord(models.Model):
- time_raised = models.DateTimeField(default=timezone.now, editable=False)
+ time_raised = models.DateTimeField(default=timezone.now, editable=False)
reference = models.CharField(unique=True, max_length=20)
description = models.TextField()
manage.py shell
we can now manage.py shell
we can now>>> from project.example.serializers import CustomerReportSerializer
>>> serializer = CustomerReportSerializer()
>>> print(repr(serializer))
diff --git a/index.html b/index.html
index 35d311040..5d9b02d93 100644
--- a/index.html
+++ b/index.html
@@ -461,8 +461,8 @@
Note: This is the documentation for the version 3.0 of REST framework. Documentation for version 2.4 is also available.
-For more details see the 3.0 release notes.
+Note: This is the documentation for the version 3.1 of REST framework. Documentation for version 2.4 is also available.
+For more details see the 3.1 release notes.