Consider:
class CouponSerializer(serializers.ModelSerializer):
courses = serializers.PrimaryKeyRelatedField(
many=True, read_only=True)
class Meta:
model = Coupon
exclude = ['users']
If I remove read_only=True, I get the error:
AssertionError: Relational field must provide a `queryset` argument, override `get_queryset`, or set read_only=`True`.
The documentation states:
The queryset used for model instance lookups when validating the field input. Relationships must either set a queryset explicitly, or set read_only=True
What is the logic underlying this requirement? Why is there no such requirement for StringRelatedField?