drf-writable-nested icon indicating copy to clipboard operation
drf-writable-nested copied to clipboard

[Question] Nested partial update with non-nullable fields.

Open DanielAviv opened this issue 6 years ago • 1 comments

I have something like:

class A(models.Model):
    x = models.IntegerField()
    y = models.IntegerField(default=0)

class B(models.Model):
    z = models.IntegerField()
    a = models.ForeignKey(A)

class BUpdateAPIView(UpdateAPIView):
   serializer_class = BUpdateSerializer
   ...

class AUpdateSerializer(ModelSerializer):
    class Meta:
         model = B
         fields = ('y', )

class BUpdateSerializer(WritableNestedModelSerializer):
    a = AUpdateSerializer()

    class Meta:
         model = B
         fields = ('z', 'a', )

And I'm trying to do a partial update (using method PATCH) on B, but it fails because x = null

DanielAviv avatar Apr 23 '19 19:04 DanielAviv

Hello @DanielAviv! The partial data updating isn't implemented well for nested serializers. I created an issue about it #79.

ruscoder avatar Apr 25 '19 02:04 ruscoder