A serializer field that accept many types of data

Hi! right now i have this serializer

class StudentPOSTSerializer(serializers.ModelSerializer):
    cohort = serializers.IntegerField(write_only=True, required=False)

I need the field cohort to accept an integer or a list of integers. Is that possible?

If you’re looking at a situation where you’ve got serialized data coming in with a field that could be either, I’d probably create a custom field with a to_internal_value method that, when presented with a single integer, converts it into a list of length 1.

Side note: This forum may not be the best place to get questions answered about the Django Rest Framework. See Support for their recommendations.