Подскажите пожалуйста как работает сериализация.
models.py
class Family(models.Model): class Meta: verbose_name_plural = 'family' name = models.CharField(max_length=10) def __str__(self): class Host(models.Model): hostname = models.CharField('Hostname', max_length=200) family = models.ManyToManyField(Family, related_name="hosts") def __str__(self): return self.hostname
serializer.py
class FamilySerializer(ModelSerializer): class Meta: model = Family fields = ('name',) class HostSerializer(ModelSerializer): class Meta: model = Host fields = ('hostname', 'family') depth = 2
"family": [ { "id": 7, "name": "cisco" } ],
"family": "cisco"