[Answer]-How to declare and call a model method navigating through relations in django?


It should be free_places(self):

You can define the method as a property and then call that from the template:


Last example in that code block

def _free_places(self):
    places = 0
    for r in self.rooms:
        x = r.beds - ((r.tenant).size())
        places = places + x
    return places
free_places = property(_free_places)

Leave a comment