Q:

django serialize and deserialize object with SerializerMethodField

I'm using djangorestframework 3.7.7
I have 'Item' model which doesn't include 'owner' field.
The item model serializer looks something like this:
class ItemSerializer(serializers.ModelSerializer):
    id = serializers.CharField(required=False, max_length=1000, allow_null=True)
    owner = serializers.SerializerMethodField()
    class Meta:
        model = Item

    fields = [
        'id',
        'owner'
    ]

    def get_owner(self, item):
        return item.package.owner if item.package else None

When serializing it using:
ser_item = ItemSerializer(item)

I get the owner field in ser_item.data
But when deserializing, using:
serializer = ItemSerializer(data=ser_item)
serializer.is_valid(raise_exception=True)
obj = Item(**serializer.validated_data)

The obj doesn't contain the owner field. 
It doesn't even seem to go through the serializer (when debugging).
Any idea how can I deserialize so this fields, which is not part of the model will be part of the new instance?

A:

If you need to make owner as a property of object after deserialization then you need to update create, update methods based on requirement as mentioned in documentation.
In your case, serializer would become something like:
class ItemSerializer(serializers.ModelSerializer):
    id = serializers.CharField(required=False, max_length=1000, allow_null=True)
    owner = serializers.SerializerMethodField()
    class Meta:
        model = Item

        fields = [
           'id',
           'owner'
        ]

    def get_owner(self, item):
         return item.package.owner if item.package else None

    def update(self, instance, validated_data):
        instance.email = validated_data.get('owner', 'default')
        return instance

    # same way for create

Also, while deserializing you need to provide ser_item.data, instead of ser_item.  Also save the serializer to trigger update/ create method. ( Thank you @user2880391 for pointing that out, I also missed this.) 
serializer = ItemSerializer(data=ser_item.validated_data)
serializer.save()

