diff --git a/.travis.yml b/.travis.yml index a5b6d7d91..7dec96cf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,8 @@ env: - TOX_ENV=py2.6-django1.4 install: - - "pip install tox --download-cache $HOME/.pip-cache" +# Virtualenv < 14 is required to keep the Python 3.2 builds running. + - "pip install tox 'virtualenv<14' --download-cache $HOME/.pip-cache" script: - tox -e $TOX_ENV diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 8979339c1..b0150f3d5 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -73,6 +73,12 @@ except ImportError: from collections import UserDict from collections import MutableMapping as DictMixin +# http responses move in Python 3 +try: + from httplib import responses +except ImportError: + from http.client import responses + # Try to import PIL in either of the two ways it can end up installed. try: from PIL import Image diff --git a/rest_framework/response.py b/rest_framework/response.py index 3ec63f403..27098d75b 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -8,7 +8,7 @@ from __future__ import unicode_literals import django from django.template.response import SimpleTemplateResponse from django.utils import six -import httplib +from rest_framework.compat import responses class Response(SimpleTemplateResponse): """ @@ -80,7 +80,7 @@ class Response(SimpleTemplateResponse): """ # TODO: Deprecate and use a template tag instead # TODO: Status code text for RFC 6585 status codes - return httplib[self.status_code] + return responses.get(self.status_code, '') def __getstate__(self): """ diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index c7a5de987..29df9299d 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1079,12 +1079,12 @@ class ModelSerializer(Serializer): fk_field = obj._meta.get_field_by_name(accessor_name)[0].field.name setattr(related, fk_field, obj) self.save_object(related) + elif isinstance(related, list): + # Many to One/Many + getattr(obj, accessor_name).add(*related, bulk=False) else: # Reverse FK or reverse one-one - try: - setattr(obj, accessor_name, related) - except ValueError: - getattr(obj, accessor_name).add(*related, bulk=False) + setattr(obj, accessor_name, related) del(obj._related_data)