1👍
✅
Why not overriding validate()
on serializer? See Object-level validation
class WorkloadPutSerializer(serializers.Serializer):
vdi = VdiSerializer(required = False)
db = DbSerializer(required = False)
pk = serializers.IntegerField(read_only=True)
def validate(self, data):
"""
Check if at least one of data['vdi'] or data['vm']
exists and then return the data. Otherwise raise
ValidationError.
"""
if data['vdi'] or data['vm']:
return data
else:
raise serializers.ValidationError("No No No")
Source:stackexchange.com