A
A
Alexander2018-04-01 09:14:00
Django
Alexander, 2018-04-01 09:14:00

Is it possible to tell ModelSerializer not to create data but to update (DRF)?

There is a model:

class MyModel(...):
    first_field = models.ForeignKey(...)
    second_field = models.ForeignKey(...)
    status = models.CharField(max_length=255)

    class Meta:
        unique_together = ('first_field', 'second_filed', 'status')

first_field and second_filed are the primary key for this table.
Serializer:
class MyModelModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = MyModel
        fields = '__all__'

when calling: MyModelModelSerializer(data=request.data, context={'request': request})
Is it possible to understand that the data needs to be updated or created? at the serializer level?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-04-02
@JekaROSS

If I'm not mistaken, then just pass instance to the serializer constructor:
Here is an example of a source code from off. repository

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question