'Django Rest Framework API with Primary Key Related Field serializer says that field is required even when it is included

I have an API with Django Rest Framework and one of my Serializers looks like this:

class InputtedWaittimeSerializer(serializers.ModelSerializer):
    restaurant = serializers.PrimaryKeyRelatedField(many=False, queryset=Restaurant.objects.all(), read_only = False)
    reporting_user = serializers.PrimaryKeyRelatedField(many=False, queryset=AppUser.objects.all(), read_only = False)
    class Meta:
        model = InputtedWaittime
        fields = ['id', 'restaurant', 'wait_length', 'reporting_user', 'accuracy', 'point_value', 'post_time', 'arrival_time', 'seated_time']
        depth = 1
        read_only_fields = ('id','accuracy','point_value','post_time')

Restaurant and AppUser are both different models, and the Serializer model (InputtedWaittime) has fields that are foreign keys to the first two models. I added a PrimaryKeyRelatedField for each of these foreign key relations so that the API would only show their primary keys. So, a GET request to this API looks like this:

{
    "id": 1,
    "restaurant": 1,
    "wait_length": 22,
    "reporting_user": 1,
    "accuracy": 1.0,
    "point_value": 10,
    "post_time": "2022-05-08T23:39:11.414114Z",
    "arrival_time": "2022-05-08T23:39:05Z",
    "seated_time": null
}

Where reporting_user and restaurant just have the primary keys to their entries in the other models. However, I have run into a problem when I try to POST data to this API. When I send data in with just the primary keys for the foreign key fields, the API just returns this response:

{"restaurant":["This field is required."],"reporting_user":["This field is required."]}%   

I used this command to POST data to this API: curl -X POST -F ‘restaurant=1’ -F ‘wait_length=22’ -F ‘reporting_user=1’ http://127.0.0.1:8000/api/inputtedwaittimes/ -H 'Authorization: Token ___TOKEN___' I am not sure why it is saying that the restaurant and reporting_user fields are required when I still included their primary keys. Thank you for any help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source