From 268f60999cdca46e6541f5acc35fbbe08b85f477 Mon Sep 17 00:00:00 2001 From: Juan Riaza Date: Thu, 10 Jan 2013 15:48:22 +0100 Subject: [PATCH 01/15] unused imports --- rest_framework/tests/decorators.py | 1 - rest_framework/tests/relations_hyperlink.py | 1 - rest_framework/tests/relations_nested.py | 1 - rest_framework/tests/relations_pk.py | 1 - 4 files changed, 4 deletions(-) diff --git a/rest_framework/tests/decorators.py b/rest_framework/tests/decorators.py index bc44a45b0..5e6bce4ef 100644 --- a/rest_framework/tests/decorators.py +++ b/rest_framework/tests/decorators.py @@ -1,5 +1,4 @@ from django.test import TestCase -from django.test.client import RequestFactory from rest_framework import status from rest_framework.response import Response from rest_framework.renderers import JSONRenderer diff --git a/rest_framework/tests/relations_hyperlink.py b/rest_framework/tests/relations_hyperlink.py index ef57dc83c..579136704 100644 --- a/rest_framework/tests/relations_hyperlink.py +++ b/rest_framework/tests/relations_hyperlink.py @@ -1,4 +1,3 @@ -from django.db import models from django.test import TestCase from rest_framework import serializers from rest_framework.compat import patterns, url diff --git a/rest_framework/tests/relations_nested.py b/rest_framework/tests/relations_nested.py index 225fee882..0e129fae2 100644 --- a/rest_framework/tests/relations_nested.py +++ b/rest_framework/tests/relations_nested.py @@ -1,4 +1,3 @@ -from django.db import models from django.test import TestCase from rest_framework import serializers from rest_framework.tests.models import ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource diff --git a/rest_framework/tests/relations_pk.py b/rest_framework/tests/relations_pk.py index 589b3646c..548358603 100644 --- a/rest_framework/tests/relations_pk.py +++ b/rest_framework/tests/relations_pk.py @@ -1,4 +1,3 @@ -from django.db import models from django.test import TestCase from rest_framework import serializers from rest_framework.tests.models import ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource From 674c9029c1b0f3680bfc04dd87b58f9bd21988de Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Fri, 4 Jan 2013 05:46:30 -0600 Subject: [PATCH 02/15] Imply an additional element in infinite lists This is to allow the addition of elements without having to change existing lines of code --- docs/tutorial/1-serialization.md | 4 ++-- docs/tutorial/2-requests-and-responses.md | 2 +- docs/tutorial/3-class-based-views.md | 2 +- docs/tutorial/4-authentication-and-permissions.md | 4 ++-- docs/tutorial/5-relationships-and-hyperlinked-apis.md | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index e61fb9469..c8db8f24c 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -60,7 +60,7 @@ We'll also need to add our new `snippets` app and the `rest_framework` app to `I INSTALLED_APPS = ( ... 'rest_framework', - 'snippets' + 'snippets', ) We also need to wire up the root urlconf, in the `tutorial/urls.py` file, to include our snippet app's URLs. @@ -288,7 +288,7 @@ Finally we need to wire these views up. Create the `snippets/urls.py` file: urlpatterns = patterns('snippets.views', url(r'^snippets/$', 'snippet_list'), - url(r'^snippets/(?P[0-9]+)/$', 'snippet_detail') + url(r'^snippets/(?P[0-9]+)/$', 'snippet_detail'), ) It's worth noting that there are a couple of edge cases we're not dealing with properly at the moment. If we send malformed `json`, or if a request is made with a method that the view doesn't handle, then we'll end up with a 500 "server error" response. Still, this'll do for now. diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index 08cf91cdb..cdf6c13f3 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -117,7 +117,7 @@ Now update the `urls.py` file slightly, to append a set of `format_suffix_patter urlpatterns = patterns('snippets.views', url(r'^snippets/$', 'snippet_list'), - url(r'^snippets/(?P[0-9]+)$', 'snippet_detail') + url(r'^snippets/(?P[0-9]+)$', 'snippet_detail'), ) urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/docs/tutorial/3-class-based-views.md b/docs/tutorial/3-class-based-views.md index b115b0229..290ea5e9d 100644 --- a/docs/tutorial/3-class-based-views.md +++ b/docs/tutorial/3-class-based-views.md @@ -70,7 +70,7 @@ We'll also need to refactor our URLconf slightly now we're using class based vie urlpatterns = patterns('', url(r'^snippets/$', views.SnippetList.as_view()), - url(r'^snippets/(?P[0-9]+)/$', views.SnippetDetail.as_view()) + url(r'^snippets/(?P[0-9]+)/$', views.SnippetDetail.as_view()), ) urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md index 9576a7f0b..5793d38eb 100644 --- a/docs/tutorial/4-authentication-and-permissions.md +++ b/docs/tutorial/4-authentication-and-permissions.md @@ -77,7 +77,7 @@ We'll also add a couple of views. We'd like to just use read-only views for the Finally we need to add those views into the API, by referencing them from the URL conf. url(r'^users/$', views.UserList.as_view()), - url(r'^users/(?P[0-9]+)/$', views.UserInstance.as_view()) + url(r'^users/(?P[0-9]+)/$', views.UserInstance.as_view()), ## Associating Snippets with Users @@ -134,7 +134,7 @@ And, at the end of the file, add a pattern to include the login and logout views urlpatterns += patterns('', url(r'^api-auth/', include('rest_framework.urls', - namespace='rest_framework')) + namespace='rest_framework')), ) The `r'^api-auth/'` part of pattern can actually be whatever URL you want to use. The only restriction is that the included urls must use the `'rest_framework'` namespace. diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index 216ca4338..c4c034956 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -116,7 +116,7 @@ After adding all those names into our URLconf, our final `'urls.py'` file should url(r'^snippets/(?P[0-9]+)/$', views.SnippetDetail.as_view(), name='snippet-detail'), - url(r'^snippets/(?P[0-9]+)/highlight/$' + url(r'^snippets/(?P[0-9]+)/highlight/$', views.SnippetHighlight.as_view(), name='snippet-highlight'), url(r'^users/$', @@ -130,7 +130,7 @@ After adding all those names into our URLconf, our final `'urls.py'` file should # Login and logout views for the browsable API urlpatterns += patterns('', url(r'^api-auth/', include('rest_framework.urls', - namespace='rest_framework')) + namespace='rest_framework')), ) ## Adding pagination From 8efd9563a6d207619ebbd066292fa910023189ae Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Fri, 4 Jan 2013 05:47:27 -0600 Subject: [PATCH 03/15] Some comment on the tutorial repository --- docs/tutorial/1-serialization.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index c8db8f24c..d12f7935f 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -8,7 +8,7 @@ The tutorial is fairly in-depth, so you should probably get a cookie and a cup o --- -**Note**: The final code for this tutorial is available in the [tomchristie/rest-framework-tutorial][repo] repository on GitHub. There is also a sandbox version for testing, [available here][sandbox]. +**Note**: The code for this tutorial is available in the [tomchristie/rest-framework-tutorial][repo] repository on GitHub. As pieces of code are introduced, they are committed to this repository. The completed implementation is also online as a sandbox version for testing, [available here][sandbox]. --- @@ -73,7 +73,7 @@ Okay, we're ready to roll. ## Creating a model to work with -For the purposes of this tutorial we're going to start by creating a simple `Snippet` model that is used to store code snippets. Go ahead and edit the `snippets` app's `models.py` file. +For the purposes of this tutorial we're going to start by creating a simple `Snippet` model that is used to store code snippets. Go ahead and edit the `snippets` app's `models.py` file. Note: Good programming practices include comments. Although you will find them in our repository version of this tutorial code, we have omitted them here to focus on the code itself. from django.db import models from pygments.lexers import get_all_lexers From 12efd78fcf40ea8acf95259ffc5269bd9f360d2f Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Wed, 9 Jan 2013 11:19:12 -0600 Subject: [PATCH 04/15] Bringing up the Web API --- docs/tutorial/1-serialization.md | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index d12f7935f..28aaea4d7 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -295,9 +295,38 @@ It's worth noting that there are a couple of edge cases we're not dealing with p ## Testing our first attempt at a Web API -**TODO: Describe using runserver and making example requests from console** +Now we can start up a sample server that serves our snippets. -**TODO: Describe opening in a web browser and viewing json output** +Quit out of the shell + + quit() + +and start up Django's development server + + python manage.py runserver + + Validating models... + + 0 errors found + Django version 1.4.3, using settings 'tutorial.settings' + Development server is running at http://127.0.0.1:8000/ + Quit the server with CONTROL-C. + +In another terminal window, we can test the server. + +We can get a list of all of the snippets (we only have one at the moment) + + curl http://127.0.0.1:8000/snippets/ + + [{"id": 1, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"}] + +or we can get a particular snippet by referencing its id + + curl http://127.0.0.1:8000/snippets/1/ + + {"id": 1, "title": "", "code": "print \"hello, world\"\n", "linenos": false, "language": "python", "style": "friendly"} + +Similarly, you can have the same json displayed by referencing these URLs from your favorite web browser. ## Where are we now From 7dd5c56f225c7fe97a23101eea1bb839110d8ed2 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Thu, 10 Jan 2013 16:16:30 -0600 Subject: [PATCH 05/15] Make the whitespace uniform --- docs/tutorial/1-serialization.md | 3 --- docs/tutorial/2-requests-and-responses.md | 3 --- 2 files changed, 6 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 28aaea4d7..db6db2da6 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -202,8 +202,6 @@ Open the file `snippets/serializers.py` again, and edit the `SnippetSerializer` model = Snippet fields = ('id', 'title', 'code', 'linenos', 'language', 'style') - - ## Writing regular Django views using our Serializer Let's see how we can write some API views using our new Serializer class. @@ -229,7 +227,6 @@ Edit the `snippet/views.py` file, and add the following. kwargs['content_type'] = 'application/json' super(JSONResponse, self).__init__(content, **kwargs) - The root of our API is going to be a view that supports listing all the existing snippets, or creating a new snippet. @csrf_exempt diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index cdf6c13f3..340ea28ee 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -31,7 +31,6 @@ These wrappers provide a few bits of functionality such as making sure you recei The wrappers also provide behaviour such as returning `405 Method Not Allowed` responses when appropriate, and handling any `ParseError` exception that occurs when accessing `request.DATA` with malformed input. - ## Pulling it all together Okay, let's go ahead and start using these new components to write a few views. @@ -63,7 +62,6 @@ We don't need our `JSONResponse` class anymore, so go ahead and delete that. On else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - Our instance view is an improvement over the previous example. It's a little more concise, and the code now feels very similar to if we were working with the Forms API. We're also using named status codes, which makes the response meanings more obvious. Here is the view for an individual snippet. @@ -138,7 +136,6 @@ Because the API chooses a return format based on what the client asks for, it wi See the [browsable api][browseable-api] topic for more information about the browsable API feature and how to customize it. - ## What's next? In [tutorial part 3][tut-3], we'll start using class based views, and see how generic views reduce the amount of code we need to write. From c09a579851b6d5e6c57bf32fae1c5dbd8466988e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 11 Jan 2013 08:56:49 +0000 Subject: [PATCH 06/15] Added @wackerbarth. Thanks! --- docs/topics/credits.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/topics/credits.md b/docs/topics/credits.md index 83272766e..60800c9e6 100644 --- a/docs/topics/credits.md +++ b/docs/topics/credits.md @@ -88,6 +88,7 @@ The following people have helped make REST framework great. * Juan Riaza - [juanriaza] * Michael Mior - [michaelmior] * Marc Tamlyn - [mjtamlyn] +* Richard Wackerbarth - [wackerbarth] Many thanks to everyone who's contributed to the project. @@ -211,3 +212,4 @@ You can also contact [@_tomchristie][twitter] directly on twitter. [juanriaza]: https://github.com/juanriaza [michaelmior]: https://github.com/michaelmior [mjtamlyn]: https://github.com/mjtamlyn +[wackerbarth]: https://github.com/wackerbarth From 919c5e1e01106918af9f26c506c2198fbf731923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Fri, 11 Jan 2013 20:26:44 +0100 Subject: [PATCH 07/15] Fix typo in permission_classes --- docs/api-guide/authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index c089e4e1a..afd9a2619 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -52,7 +52,7 @@ Or, if you're using the `@api_view` decorator with function based views. @api_view(['GET']) @authentication_classes((SessionAuthentication, BasicAuthentication)) - @permissions_classes((IsAuthenticated,)) + @permission_classes((IsAuthenticated,)) def example_view(request, format=None): content = { 'user': unicode(request.user), # `django.contrib.auth.User` instance. From 73c4e5c4603e24ec1ea9976a3c6152a797f8f041 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 12 Jan 2013 09:32:53 +0000 Subject: [PATCH 08/15] auto_now and auto_now_add fields should be read only by default --- rest_framework/serializers.py | 3 +++ rest_framework/tests/fields.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 rest_framework/tests/fields.py diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index da0af467f..0bacacda7 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -452,6 +452,9 @@ class ModelSerializer(Serializer): if model_field.null or model_field.blank: kwargs['required'] = False + if not model_field.editable: + kwargs['read_only'] = True + if model_field.has_default(): kwargs['required'] = False kwargs['default'] = model_field.get_default() diff --git a/rest_framework/tests/fields.py b/rest_framework/tests/fields.py new file mode 100644 index 000000000..b1a8161a6 --- /dev/null +++ b/rest_framework/tests/fields.py @@ -0,0 +1,26 @@ +""" +General tests for relational fields. +""" + +from django.db import models +from django.test import TestCase +from rest_framework import serializers + + +class TimestampedModel(models.Model): + added = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + + +class TimestampedModelSerializer(serializers.ModelSerializer): + class Meta: + model = TimestampedModel + + +class ReadOnlyFieldTests(TestCase): + def test_auto_now_fields_read_only(self): + """ + auto_now and auto_now_add fields should be readonly by default. + """ + serializer = TimestampedModelSerializer() + self.assertEquals(serializer.fields['added'].read_only, True) From d9acec3e6dd07d33f416646bc161108ea52842d6 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 12 Jan 2013 09:43:07 +0000 Subject: [PATCH 09/15] PK fields should only be read-only if they are an AutoField. Fixes #563 --- rest_framework/serializers.py | 5 +++-- rest_framework/tests/fields.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 0bacacda7..27458f968 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -415,7 +415,7 @@ class ModelSerializer(Serializer): """ Returns a default instance of the pk field. """ - return Field() + return self.get_field(model_field) def get_nested_field(self, model_field): """ @@ -452,7 +452,7 @@ class ModelSerializer(Serializer): if model_field.null or model_field.blank: kwargs['required'] = False - if not model_field.editable: + if isinstance(model_field, models.AutoField) or not model_field.editable: kwargs['read_only'] = True if model_field.has_default(): @@ -468,6 +468,7 @@ class ModelSerializer(Serializer): return ChoiceField(**kwargs) field_mapping = { + models.AutoField: IntegerField, models.FloatField: FloatField, models.IntegerField: IntegerField, models.PositiveIntegerField: IntegerField, diff --git a/rest_framework/tests/fields.py b/rest_framework/tests/fields.py index b1a8161a6..a6a059416 100644 --- a/rest_framework/tests/fields.py +++ b/rest_framework/tests/fields.py @@ -12,11 +12,20 @@ class TimestampedModel(models.Model): updated = models.DateTimeField(auto_now=True) +class CharPrimaryKeyModel(models.Model): + id = models.CharField(max_length=20, primary_key=True) + + class TimestampedModelSerializer(serializers.ModelSerializer): class Meta: model = TimestampedModel +class CharPrimaryKeyModelSerializer(serializers.ModelSerializer): + class Meta: + model = CharPrimaryKeyModel + + class ReadOnlyFieldTests(TestCase): def test_auto_now_fields_read_only(self): """ @@ -24,3 +33,11 @@ class ReadOnlyFieldTests(TestCase): """ serializer = TimestampedModelSerializer() self.assertEquals(serializer.fields['added'].read_only, True) + + def test_auto_pk_fields_read_only(self): + serializer = TimestampedModelSerializer() + self.assertEquals(serializer.fields['id'].read_only, True) + + def test_non_auto_pk_fields_not_read_only(self): + serializer = CharPrimaryKeyModelSerializer() + self.assertEquals(serializer.fields['id'].read_only, False) From 25a463be7302ae64fe1ea2a560d7bdbd022221d9 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 12 Jan 2013 10:07:11 +0000 Subject: [PATCH 10/15] Update release notes. --- docs/topics/release-notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index d883571ad..b7907ec73 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -19,10 +19,13 @@ Major version numbers (x.0.0) are reserved for project milestones. No major poi ### Master * Deprecate django.utils.simplejson in favor of Python 2.6's built-in json module. +* Bugfix: PK fields now only default to `read_only=True` if they are an AutoField or if `editable=False`. * Bugfix: Validation errors instead of exceptions when serializers receive incorrect types. * Bugfix: Validation errors instead of exceptions when related fields receive incorrect types. * Bugfix: Handle ObjectDoesNotExist exception when serializing null reverse one-to-one +**Note**: If you are using auto UUID fields as your primary keys, you probably want to make sure that the model fields correctly set `editable=False`. + ### 2.1.15 **Date**: 3rd Jan 2013 From e0440e609b818b0426df33e31318cb8c0463b65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Sat, 12 Jan 2013 14:28:16 +0100 Subject: [PATCH 11/15] Update django-filter link to pypi --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a9149cf1..1cf14f8d2 100644 --- a/README.md +++ b/README.md @@ -283,5 +283,5 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [urlobject]: https://github.com/zacharyvoase/urlobject [markdown]: http://pypi.python.org/pypi/Markdown/ [pyyaml]: http://pypi.python.org/pypi/PyYAML -[django-filter]: https://github.com/alex/django-filter +[django-filter]: http://pypi.python.org/pypi/django-filter From da85bb1ab3eedbd8df1e2fc9577ed3e2ab809c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9F?= Date: Sat, 12 Jan 2013 14:31:40 +0100 Subject: [PATCH 12/15] Update django-filter link to pypi --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 080eca6f2..497f19004 100644 --- a/docs/index.md +++ b/docs/index.md @@ -166,7 +166,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [urlobject]: https://github.com/zacharyvoase/urlobject [markdown]: http://pypi.python.org/pypi/Markdown/ [yaml]: http://pypi.python.org/pypi/PyYAML -[django-filter]: https://github.com/alex/django-filter +[django-filter]: http://pypi.python.org/pypi/django-filter [0.4]: https://github.com/tomchristie/django-rest-framework/tree/0.4.X [image]: img/quickstart.png [sandbox]: http://restframework.herokuapp.com/ From 0987bed2f74f69eccba181303689197e54836288 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Fri, 11 Jan 2013 14:04:13 -0600 Subject: [PATCH 13/15] Minor gramatical correction --- docs/tutorial/4-authentication-and-permissions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md index 5793d38eb..f6daebb7a 100644 --- a/docs/tutorial/4-authentication-and-permissions.md +++ b/docs/tutorial/4-authentication-and-permissions.md @@ -29,7 +29,7 @@ And now we can add a `.save()` method to our model class: def save(self, *args, **kwargs): """ - Use the `pygments` library to create an highlighted HTML + Use the `pygments` library to create a highlighted HTML representation of the code snippet. """ lexer = get_lexer_by_name(self.language) From 08943c3e0aad30b2f9f6b8146daa80117b7adfb3 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Sun, 13 Jan 2013 10:49:49 -0600 Subject: [PATCH 14/15] Format extensions have already been introduced. If format extensions are used, they must be used in the creation of the reverse URLs. --- docs/tutorial/5-relationships-and-hyperlinked-apis.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index c4c034956..27898f7b9 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -15,8 +15,8 @@ Right now we have endpoints for 'snippets' and 'users', but we don't have a sing @api_view(('GET',)) def api_root(request, format=None): return Response({ - 'users': reverse('user-list', request=request), - 'snippets': reverse('snippet-list', request=request) + 'users': reverse('user-list', request=request, format=format), + 'snippets': reverse('snippet-list', request=request, format=format) }) Notice that we're using REST framework's `reverse` function in order to return fully-qualified URLs. From 191135d7b06617069489fa5de4e6f519767a4ee1 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 14 Jan 2013 09:20:37 +0000 Subject: [PATCH 15/15] Version 2.1.16 --- README.md | 11 +++++++++++ docs/topics/release-notes.md | 9 +++++---- rest_framework/__init__.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1cf14f8d2..a70201661 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,17 @@ To run the tests. # Changelog +### 2.1.16 + +**Date**: 14th Jan 2013 + +* Deprecate django.utils.simplejson in favor of Python 2.6's built-in json module. +* Bugfix: `auto_now`, `auto_now_add` and other `editable=False` fields now default to read-only. +* Bugfix: PK fields now only default to read-only if they are an AutoField or if `editable=False`. +* Bugfix: Validation errors instead of exceptions when serializers receive incorrect types. +* Bugfix: Validation errors instead of exceptions when related fields receive incorrect types. +* Bugfix: Handle ObjectDoesNotExist exception when serializing null reverse one-to-one + ### 2.1.15 **Date**: 3rd Jan 2013 diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index b7907ec73..bf23fa352 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -16,16 +16,17 @@ Major version numbers (x.0.0) are reserved for project milestones. No major poi ## 2.1.x series -### Master +### 2.1.16 + +**Date**: 14th Jan 2013 * Deprecate django.utils.simplejson in favor of Python 2.6's built-in json module. -* Bugfix: PK fields now only default to `read_only=True` if they are an AutoField or if `editable=False`. +* Bugfix: `auto_now`, `auto_now_add` and other `editable=False` fields now default to read-only. +* Bugfix: PK fields now only default to read-only if they are an AutoField or if `editable=False`. * Bugfix: Validation errors instead of exceptions when serializers receive incorrect types. * Bugfix: Validation errors instead of exceptions when related fields receive incorrect types. * Bugfix: Handle ObjectDoesNotExist exception when serializing null reverse one-to-one -**Note**: If you are using auto UUID fields as your primary keys, you probably want to make sure that the model fields correctly set `editable=False`. - ### 2.1.15 **Date**: 3rd Jan 2013 diff --git a/rest_framework/__init__.py b/rest_framework/__init__.py index 1d25ee7f7..bc267fad7 100644 --- a/rest_framework/__init__.py +++ b/rest_framework/__init__.py @@ -1,3 +1,3 @@ -__version__ = '2.1.15' +__version__ = '2.1.16' VERSION = __version__ # synonym