- - - - - - -楷模
class Contact(models.Model):
email = models.EmailField()
class Client(models.Model):
name = models.CharField(max_length=256)
contact = models.ForeignKey('Contact')
class Vendor(models.Model):
name = models.CharField(max_length=256)
contact = models.ForeignKey('Contact')
-------------模型序列化器
class ContactSerializer(serializers.ModelSerializer):
class Meta:
model = Contact
class ClientSerializer(serializers.ModelSerializer):
class Meta:
model = Client
class VendorSerializer(serializers.ModelSerializer):
class Meta:
model = Vendor
“客户表格”应包含以下字段:客户模型的所有字段和联系人模型的所有字段
这可以使用单个“ClientSerializer”吗?