Let's say I'm designing a database with books (using Django's ORM, but I'm interested in the general theory of database design here as well as Django-specific advice). This is how I've designed my database so far so that there aren't any useless fields in each model:
class Book(models.Model):
author = models.ManyToManyField()
class PictureBook(Book):
illustrator = models.ManyToManyField()
class MusicBook(Book):
composer = models.ManyToManyField()
With this database design, I have an abstract model that has all universal fields stored in it, then sub-classes that have fields specific to them.
The problem is that as my project grows, I'm having to duplicate a lot of effort to handle each of the sub types rather than developing around one universal model. What I'm considering is reverting to something more like this:
class Book(models.Model):
types = (("g", "General"), ("p", "Picture"), ("m", "Music"))
type = models.CharField(max_length=10, choices=types)
author = models.ManyToManyField()
illustrator = models.ManyToManyField(blank=True)
composer = models.ManyToManyField(blank=True)
Here I would just have one Book model, which has a limited-option field that has the user choose the sub-type of the book they are adding. The problem is that then picture books have composer fields and music books have illustrator fields, and even though I can leave them blank, it feels messy to have all these superfluous fields associated with each and every DB object.
On the other hand, this would make querying way easier, as I could get grouped results with one query, then filter based on the type attribute.
I'm not very experienced at database design. Is there a general consensus on which database design schema is preferable in this type of circumstance? I'm considering redesigning from the former to the latter style, but I'm curious on more experienced developer's thoughts on which will leave me with more long-term difficulties.