def create(self, validated_data):
"""
Check that all required tags are included in tag data before creating.
"""
if ['tags', 'variant'] != sorted(validated_data.keys()):
raise serializers.ValidationError(detail={
'detail': "Create (POST) should include the 'tags' and "
"'variant' fields. Your request contains the following "
'fields: {}'.format(str(validated_data.keys()))})
if 'tags' in validated_data:
for tag in Relation.required_tags:
if tag not in validated_data['tags']:
raise serializers.ValidationError(detail={
'detail': 'Create (POST) tag data must include all '
'required tags: {}'.format(Relation.required_tags)})
return super(RelationSerializer, self).create(validated_data)
评论列表
文章目录