I'm trying to model television shows down to the episode level. Given that each level of the tree (network, series, season, episode) has different fields, I want to use different model types for each level.
My initial approach was to keep track of the parent with a foreign key at each level (this is a simplified approach, I know there would be other fields):
class Network(models.Model):
...
class Series(models.Model):
network = models.ForeignKey(Network)
...
class Season(models.Model):
series = models.ForeignKey(Series)
...
class Episode(models.Model):
season = models.ForeignKey(Season)
...
But if I want to get the network of a specific episode, I have to lookup Episode->Season->Series->Network. That seems inefficient and poorly architected because it requires a lot of queries.
I saw the library django-mptt
, but this requires that your tree be built of a single model type.
From a design standpoint, what's the standard way to structure this type of tree? What are the tradeoffs of different approaches?