In Django, I have the following models.
class Genus(models.Model):
genus_name=models.CharField(max_length=30)
...
class HostSpecies(models.Model):
species_genus=models.ForeignKey(Genus)
...
class HostStrain(models.Model):
strain_species=models.ForeignKey(HostSpecies)
strain_name=models.CharField(max_length=50)
...
Now I'm trying to use Django REST Framework to serialize the the HostStrain model as follows.
class HostStrainSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = HostStrain
fields = ('strain_species__species_genus','strain_species','strain_name')
But the standard double-underscore notation in Django doesn't seem to work here, since I get the error:
Field name
strain_species__species_genusis not valid for modelHostStrain.
I'd like to include a link to (or at least the __unicode__ from) the Genus model in my HostStrain serialization.
So how do I follow multi-level relationships in Django REST Framework's serialization?