Reverse query GeoJSONLayerView Django GeoJson

I have a model that looks like this:

class Site(models.Model):
    site_id = models.TextField(primary_key=True)
    site_name = models.TextField()
    region = models.TextField(blank=True, null=True)
    ccamlr_id = models.TextField()
    latitude = models.DecimalField(max_digits=5, decimal_places=3)
    longitude = models.DecimalField(max_digits=6, decimal_places=3)
    centroid = models.GeometryField(blank=True, null=True)

class SiteSpecies(models.Model):
    site_species_id = models.AutoField(primary_key=True)
    site = models.ForeignKey(Site, models.DO_NOTHING, blank=True, null=True,related_name="sites")
    species = models.ForeignKey('Species', models.DO_NOTHING, blank=True, null=True)

class Species(models.Model):
    species_id = models.TextField(primary_key=True)
    common_name = models.TextField()
    genus = models.TextField(blank=True, null=True)
    species = models.TextField(blank=True, null=True)

And I'm rendering these sites as a GeoJSONLayerView like this:

class MapLayer(GeoJSONLayerView):        
    def get_queryset(self):
        X = Site.objects.all() 
        return X
    geometry_field = 'centroid'
    srid = '3031'
    properties = ['site_name','ccamlr_id']

What I'm trying to do is use the reverse lookup here so when I get the properties for this layer view, I also get Species in the output JSON. I was thinking something like this:

class MapLayer(GeoJSONLayerView):        
    def get_queryset(self):
        X = Site.objects.all() 
        return X
    geometry_field = 'centroid'
    srid = '3031'
    properties = ['site_name','ccamlr_id','sites.all.species_id']

But that doesn't seem to work. Nor does 'sites__all__species_id'

Thanks in advance, folks.

Back to Top