title: Django model design using ForeignKey and ManyToMany
body: <p>I'm stuck and need some fresh eyes on my model design. I can't seem to wrap my head around how best to design this. </p>
  
  <p>Reqs:</p>
  
  <ul>
  <li>Each project can have several tiers of service active at once, with the others being set to off. None are mutually exclusive</li>
  <li>The tiers are the same for all projects.</li>
  <li>I need to keep track of what tiers are active on a particular project.</li>
  <li><s>I need to be able to associate a charge date for the project with active tiers</s>. See below for charge date clarification.</li>
  <li>The project and tiers 'active' fields are not related.</li>
  <li>See edit for more thoughts on my reqs.</li>
  </ul>
  
  <p>Here's the models:</p>
  
  <pre><code>class Project(models.Model):
      name = models.CharField('project name', max_length=128)
      company = models.ForeignKey('Company', related_name='projects')
      # A project could have more than one instance
      instances = models.ManyToManyField(Instance, related_name='projects') 
      type = models.CharField(max_length=128, blank=True)
      start_date = models.DateField(null=True, auto_now=False, auto_now_add=False)
      end_date = models.DateField(null=True, auto_now=False, auto_now_add=False)
      active = models.BooleanField()
  
  class Tier(models.Model):
      TIERS = (('TI1', 'tier1'),
              ('TI2', 'tier2'),
              ('TI3', 'tier3'),
              ('TI4', 'tier4'),
              ('TI5', 'tier5'))
  
      name = models.CharField(max_length=3, choices=TIERS)
      active = models.BooleanField()
  
  class TierHistory(models.Model):
  
      project = models.ForeignKey(Project, related_name='tier_history') 
      tiers = models.ManyToManyField(Tier)
      charge_date = models.DateField(null=True, auto_now=False, auto_now_add=True)
      contact = models.ForeignKey(Contact)
  </code></pre>
  
  <p>An edit to clear things up:</p>
  
  <p>The problem I'm having is that given the current design, I don't feel like I'm keeping track of tiers and if they're active in the best way possible. That is the main goal in all of this; to know what tiers are active on a project, and conversely be able to see what projects have ever had active any particular tier. </p>
  
  <p>Given my current design, I can't set tier 2 active on project 1 and inactive on project 2. </p>
  
  <ul>
  <li>A project can have multiple tiers active simultaneously. </li>
  <li>The charge date will be for each tier. I realized that I read my spec wrong. </li>
  <li>I need to be able to report, "project 1 has been using tier 1 for 3 months, tier 2 for 6 months and has never used tier 5"</li>
  <li>I need to be able to report, "project 1 and project 2 have tier 1 active now, project 1 had tier 4 active for 1 month, project 3 and is the only project currently using tier 5"</li>
  </ul>