我有一个这样的模型:
## model:
class Product(models.Model):
id = models.PositiveIntegerField(unique = True)
price = models.ForeignKey(Price, on_delete = models.CASCADE, null = True, blank = True)
## serializer:
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ["id", "price",]
它在 API 的模板中显示如下:
我明白了,这是因为模型字段类型的性质。这里有两个问题: