[Django]-How to fix 'TypeError: __init__() got an unexpected keyword argument 'sender''

4๐Ÿ‘

โœ…

You are supposed to pass a Message model instance to MessageSerializer or a dict containing data with the keys specified in fields.

In case you want to pass a dict, pass the dict to data keyword.

message_dict = {'sender': request.user, 'chat_room': ChatRoom.objects.get(id=request.data['chat_room_id']), 'content': MessageContent(text=request.data['text'])}
message_serializer = MessageSerializer(data=message_dict)

if message_serializer.is_valid():
    message_serializer.save()

Make sure you have create method implemented in your MessageSerializer.

0๐Ÿ‘

In the model.py file in one of the class attributes change

identification = models.IntegerField()

In the model.py file in one of the class attributes change

identification = models.IntegerField ()

Do not leave anything inside the parentheses, then in the console check with the following command

python manage.py check application_name
๐Ÿ‘คJohanna Farfan

Leave a comment