aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorTom Christie2014-12-02 12:46:47 +0000
committerTom Christie2014-12-02 12:46:47 +0000
commit54b7b32818fc9b8872b65d25d5684c72b8e60ae0 (patch)
treef2234a5eeee59d745abe876670653b7d1cc0973a /rest_framework/serializers.py
parent79e18a2a06178e8c00dfafc1cfd062f2528ec2c1 (diff)
parentad060aa360fa2ed33bd83cbb419d7b996a428726 (diff)
downloaddjango-rest-framework-54b7b32818fc9b8872b65d25d5684c72b8e60ae0.tar.bz2
Merge branch 'fixes/2013' of git://github.com/gregmuellegger/django-rest-framework into gregmuellegger-fixes/2013
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index a4140c0f..143d205d 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -35,6 +35,7 @@ from rest_framework.validators import (
)
import copy
import inspect
+import sys
import warnings
# Note: We do the following so that users of the framework can use this style:
@@ -653,7 +654,18 @@ class ModelSerializer(Serializer):
if relation_info.to_many and (field_name in validated_attrs):
many_to_many[field_name] = validated_attrs.pop(field_name)
- instance = ModelClass.objects.create(**validated_attrs)
+ try:
+ instance = ModelClass.objects.create(**validated_attrs)
+ except TypeError as exc:
+ msg = (
+ 'The mentioned argument might be a field on the serializer '
+ 'that is not part of the model. You need to override the '
+ 'create() method in your ModelSerializer subclass to support '
+ 'this.')
+ six.reraise(
+ type(exc),
+ type(exc)(str(exc) + '. ' + msg),
+ sys.exc_info()[2])
# Save many-to-many relationships after the instance is created.
if many_to_many: