diff options
| author | Tom Christie | 2013-04-30 08:24:33 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-04-30 08:24:33 +0100 |
| commit | 21ae3a66917acf4ea57e8f7940ce1a6823a2ce92 (patch) | |
| tree | bd4cef8d397b6a51ca2eae044b0f042949c92acc /docs | |
| parent | 81c3b4f250e389c29bdaa7da07c4860e2175136d (diff) | |
| download | django-rest-framework-21ae3a66917acf4ea57e8f7940ce1a6823a2ce92.tar.bz2 | |
Drop out attribute
Diffstat (limited to 'docs')
| -rwxr-xr-x | docs/api-guide/serializers.md | 8 | ||||
| -rw-r--r-- | docs/index.md | 20 | ||||
| -rw-r--r-- | docs/topics/2.3-announcement.md | 21 |
3 files changed, 28 insertions, 21 deletions
diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 2797b5f5..c48461d8 100755 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -374,16 +374,20 @@ Returns the field instance that should be used to represent the pk field. ### get_nested_field -**Signature**: `.get_nested_field(self, model_field)` +**Signature**: `.get_nested_field(self, model_field, related_model, to_many)` Returns the field instance that should be used to represent a related field when `depth` is specified as being non-zero. +Note that the `model_field` argument will be `None` for reverse relationships. The `related_model` argument will be the model class for the target of the field. The `to_many` argument will be a boolean indicating if this is a to-one or to-many relationship. + ### get_related_field -**Signature**: `.get_related_field(self, model_field, to_many=False)` +**Signature**: `.get_related_field(self, model_field, related_model, to_many)` Returns the field instance that should be used to represent a related field when `depth` is not specified, or when nested representations are being used and the depth reaches zero. +Note that the `model_field` argument will be `None` for reverse relationships. The `related_model` argument will be the model class for the target of the field. The `to_many` argument will be a boolean indicating if this is a to-one or to-many relationship. + ### get_field **Signature**: `.get_field(self, model_field)` diff --git a/docs/index.md b/docs/index.md index 931d6114..12e39153 100644 --- a/docs/index.md +++ b/docs/index.md @@ -79,34 +79,26 @@ Let's take a look at a quick example of using REST framework to build a simple m We'll create a read-write API for accessing users and groups. -Here's our `views.py` module: +Here's our project's root `urls.py` module: from django.conf.urls.defaults import url, patterns, include from django.contrib.auth.models import User, Group from rest_framework import viewsets, routers - # ViewSets define the view behavior. class UserViewSet(viewsets.ModelViewSet): - queryset = User.objects.all() - fields = ('url', 'email', 'is_staff', 'groups') - + model = User class GroupViewSet(viewsets.ModelViewSet): - queryset = Group.objects.all() - fields = ('url', 'name') - -And our `urls.py` setup: - - from django.conf.urls.defaults import url, patterns, include - from myapp import views - from rest_framework import routers - + model = Group + + # Routers provide an easy way of automatically determining the URL conf router = routers.DefaultRouter() router.register(r'users', views.UserViewSet, name='user') router.register(r'groups', views.GroupViewSet, name='group') + # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browseable API. urlpatterns = patterns('', diff --git a/docs/topics/2.3-announcement.md b/docs/topics/2.3-announcement.md index 45095582..5ed63f05 100644 --- a/docs/topics/2.3-announcement.md +++ b/docs/topics/2.3-announcement.md @@ -4,7 +4,6 @@ REST framework 2.3 is geared towards making it easier and quicker to build your ## ViewSets & Routers -**TODO** ## Easier Serializers @@ -132,13 +131,21 @@ If you've been customizing this behavior, for example perhaps to use `rst` marku Note that the relevant methods have always been private APIs, and the docstrings called them out as intended to be deprecated. +## ModelSerializers and reverse relationships + +The support for adding reverse relationships to the `fields` option on a `ModelSerializer` class means that the `get_related_field` and `get_nested_field` method signatures have now changed. + +In the unlikely event that you're providing a custom serializer class, and implementing these methods you should note the new call signature for both methods is now `(self, model_field, related_model, to_many)`. For revese relationships `model_field` will be `None`. + +The old-style signature will continue to function but will raise a `PendingDeprecationWarning`. + --- # Other notes -## Explict view attributes +## More explicit style -The usage of `model` attribute in generic Views is still supported, but it's usage is being discouraged in favour of the more explict `queryset` attribute. +The usage of `model` attribute in generic Views is still supported, but it's usage is being discouraged in favour of the setting the mode explict `queryset` and `serializer_class` attributes. For example, the following is now the recommended style for using generic views: @@ -146,9 +153,9 @@ For example, the following is now the recommended style for using generic views: queryset = MyModel.objects.all() serializer_class = MyModelSerializer -Using an explict `queryset` attribute makes the functioning of the view more clear than using the shortcut `model` attribute. +Using an explict `queryset` and `serializer_class` attributes makes the functioning of the view more clear than using the shortcut `model` attribute. -It also makes the usage of an overridden `get_queryset()` method more obvious. +It also makes the usage of the `get_queryset()` or `get_serializer_class()` methods more obvious. class AccountListView(generics.RetrieveAPIView): serializer_class = MyModelSerializer @@ -167,6 +174,10 @@ It also makes the usage of an overridden `get_queryset()` method more obvious. The 2.3 release series will be the last series to provide compatiblity with Django 1.3. +## Version 2.2 API changes + +All API changes in 2.2 that previously raised `PendingDeprecationWarning` will now raise a `DeprecationWarning`, which is loud by default. + ## What comes next? The plan for the next few months is to concentrate on addressing outstanding tickets. 2.4 is likely to deal with relatively small refinements to the existing API. |
