I am pulling my hair out here because this isn't working for me and seems like it should be.
I am using Django-Piston to develop an API and have 2 models, Building and Building Area.
BuildingArea has a ForeignKey to Building as there are multiple areas in a building. The 'related_name' property for the FK is 'areas' so I can access the BuildingAreas from a given Building.
The problem is that it all looks fine in Admin but when I hit the /api/building.json endpoint, all I get it the Building object without the nested BuildingArea objects included in the JSON.
I would have thought that Django-Piston would follow reverse FK fields by default or am I missing something?
handlers.py
class BuildingHandler(BaseHandler):
allowed_methods = ('GET',)
model = Building
def read(self, name=None):
return self.model.objects.all()
models.py
class Building(models.Model):
address = models.CharField(max_length=255)
def __unicode__(self):
return self.address
class BuildingArea(models.Model):
display_name = models.CharField(max_length=30)
building = models.ForeignKey(Building, related_name='areas')
def __unicode__(self):
return self.display_name