aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorTom Christie2014-12-02 13:05:09 +0000
committerTom Christie2014-12-02 13:05:09 +0000
commit41045c1c2347cb7fd37081b40053df747304b286 (patch)
tree9cc8e92aa9683be5ff7f61d043756cd7b1f26515 /rest_framework/serializers.py
parent79e18a2a06178e8c00dfafc1cfd062f2528ec2c1 (diff)
parent76ac641fbd6c9d7dff5da3c551c3fd1ef7dedd2e (diff)
downloaddjango-rest-framework-41045c1c2347cb7fd37081b40053df747304b286.tar.bz2
Merge branch 'gregmuellegger-fixes/2013'
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index a4140c0f..d417ca80 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -653,7 +653,24 @@ 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 = (
+ 'Got a `TypeError` when calling `%s.objects.create()`. '
+ 'This may be because you have a writable field on the '
+ 'serializer class that is not a valid argument to '
+ '`%s.objects.create()`. You may need to make the field '
+ 'read-only, or override the %s.create() method to handle '
+ 'this correctly.\nOriginal exception text was: %s.' %
+ (
+ ModelClass.__name__,
+ ModelClass.__name__,
+ self.__class__.__name__,
+ exc
+ )
+ )
+ raise TypeError(msg)
# Save many-to-many relationships after the instance is created.
if many_to_many: