I'm building a webapp with django with the following models:
class Business(models.Model):
...
class Branch(models.Model):
business = models.ForeignKey(Business)
...
class Event(models.Model):
branch = models.ForeignKey(Branch)
My questions is how can I get all events by their business (not their branch), and if it possible to do so in a DB query.
Thanks!
Django querysets allow you to use the "__" notation to access relationships. You can take it to any depth and read more about it here.
Any of the following should work in your case: