I have some fields on a model that won't always be filled in (e.g., the actual completion date and costs until the project is over). Because of this, I thought I'd split the model into two:
- Model #1: Dense table containing frequently searched and always completed fields
- Model #2: Sparse table containing infrequently searched and not always completed fields
Questions
- Am I thinking correctly in splitting this into two models/tables?
- Should I use Django's Multi-table Inheritance, or should I explicitly define a
OneToOneField
? Why?
Configuration
- Django version 1.3.1
Models
Using Django's Multi-table Inheritance
class Project(models.Model):
project_number = models.SlugField(max_length=5, blank=False,
primary_key=True)
budgeted_costs = models.DecimalField(max_digits=10, decimal_places=2)
class ProjectExtendedInformation(Project):
submitted_on = models.DateField(auto_now_add=True)
actual_completion_date = models.DateField(blank=True, null=True)
actual_project_costs = models.DecimalField(max_digits=10, decimal_places=2,
blank=True, null=True)
Using an Explicit OneToOneField
class Project(models.Model):
project_number = models.SlugField(max_length=5, blank=False,
primary_key=True)
budgeted_costs = models.DecimalField(max_digits=10, decimal_places=2)
class ProjectExtendedInformation(models.Model):
project = models.OneToOneField(CapExProject, primary_key=True)
submitted_on = models.DateField(auto_now_add=True)
actual_completion_date = models.DateField(blank=True, null=True)
actual_project_costs = models.DecimalField(max_digits=10, decimal_places=2,
blank=True, null=True)