0

I am trying to supply data to serializer related field but it keeps throwing a validation error which says the field is required even when I supply a value for it through postman. I honestly don't know what I am doing wrong.

Here's are my serializer;

class ProjectFileSerializer(serializers.ModelSerializers):
    class Meta:
        model = ProjectFile
        fields = ['project', 'file']


class ProjectSerializer(serializers.ModelSerializer):
    project_file = ProjectFileSerializer(write_only=True, many=True)
    class Meta:
        model = Project
        fields = ['title', 'category', 'budget', 'project_file']
David
  • 19
  • 5
  • can you share full error – Ankit Tiwari May 23 '21 at 10:11
  • Here's the exact error I get. { "project_file": [ "This field is required." ] } – David May 23 '21 at 10:58
  • you did not added this field in your question – Ankit Tiwari May 23 '21 at 10:59
  • you can set required to false if you want – Ankit Tiwari May 23 '21 at 11:00
  • @AnkitTiwari I listed the field in my ProjectSerializer fields. – David May 23 '21 at 11:02
  • @AnkitTiwari I actually need the field required. What I am trying to do is force the user to provide a project file while uploading a project. – David May 23 '21 at 11:04
  • Hello @David i don't know why you are not able to access your uploaded file in serializers maybe you missed some thing you can follow these post if you want to know what you are missing https://stackoverflow.com/a/20473684/14457833 , https://www.geeksforgeeks.org/file-upload-fields-in-serializers-django-rest-framework/ – Ankit Tiwari May 23 '21 at 11:31
  • and i am sorry that i can't help you about this because i don't know much about file uploading in using django rest – Ankit Tiwari May 23 '21 at 11:33
  • Thank you for the assist @AnkitTiwari. I just checked the references (URLs) you dropped; what I actually meant by "uploading" is when a user is trying to save a project. – David May 23 '21 at 11:45

0 Answers0