def _check_tag_data(self, instance, validated_data):
tag_data = validated_data['tags']
# For PUT, check that special tags are retained and unchanged.
if not self.partial:
for tag in instance.special_tags:
if tag in instance.tags and tag not in tag_data:
raise serializers.ValidationError(detail={
'detail': 'PUT requests must retain all special tags. '
'Your request is missing the tag: {}'.format(tag)})
# Check that special tags are unchanged.
for tag in instance.special_tags:
if (tag in instance.tags and tag in tag_data and
tag_data[tag] != instance.tags[tag]):
raise serializers.ValidationError(detail={
'detail': 'Updates (PUT or PATCH) must not attempt '
'to change the values for special tags. Your request '
'attempts to change the value for tag '
"'{}' from '{}' to '{}'".format(
tag, instance.tags[tag], tag_data[tag])})
return tag_data
评论列表
文章目录