[Django]-Django Rest Framework error: {"user":["This field is required."]

11👍

class ItemSerializer(serializers.HyperlinkedModelSerializer):
     user = UserDetailsSerializer()
     category = CategorySerializer(many=True)
     thecomments = CommentSerializer(many=True)
     timestamp = serializers.SerializerMethodField('get_mytimestamp')

     def get_mytimestamp(self, obj):
         return time.mktime(datetime.datetime.now().timetuple())

     class Meta:
         model = Item

         fields = [
         "url",
         "user",
         "timestamp",
         "categories",
         "thecomments",
         ]
        extra_kwargs = {'user': {'required': False}}

add extra_kwargs = {'user': {'required': False}} to your serializer Meta

👤Ykh

0👍

i had the same issue.
added extra_kwargs = {'user': {'required': False}} to serializer Meta class and it worked

Leave a comment