During serializer generation, when a relationship is nullable, the allow_null argument should be passed into the nested serializer when it's instantiated.
class Owner(models.Model):
name = models.CharField(max_length=100)
class Widget(models.Model):
name = models.CharField(max_length=100)
owner = models.ForeignKey(Owner, null=True, on_delete=models.SET_NULL)
spec = [
"name",
{"owner": ["name"]}
]
This results in
WidgetSerializer():
name = CharField(allow_null=True, max_length=100, read_only=True, required=False)
owner = WidgetOwnerSerializer(read_only=True):
name = CharField(max_length=100, read_only=True)
But should be
WidgetSerializer():
name = CharField(allow_null=True, max_length=100, read_only=True, required=False)
owner = WidgetOwnerSerializer(allow_null=True, read_only=True):
name = CharField(max_length=100, read_only=True)
During serializer generation, when a relationship is nullable, the
allow_null
argument should be passed into the nested serializer when it's instantiated.This results in
But should be