title: Django models and primary-foreign key relationships
body: <p>I'm writing a Django app that uses existing legacy data combined with a remapping of tables and relationships.  I've been given a table containing the primary-foreign key relationships between the tables, but am having trouble understanding how to adapt it to Django models.</p>
  
  <p>For example, a table <code>country_metrics</code> is defined as</p>
  
  <pre><code>+-------------+---------------+------+-----+---------+-------+
  | Field       | Type          | Null | Key | Default | Extra |
  +-------------+---------------+------+-----+---------+-------+
  | ContractNum | varchar(10)   | NO   |     | NULL    |       |
  | fips        | varchar(5)    | NO   |     | NULL    |       |
  | metric_id   | int(10)       | NO   |     | NULL    |       |
  | time_id     | int(10)       | NO   |     | NULL    |       |
  | value       | decimal(12,3) | NO   |     | NULL    |       |
  | eff_date    | date          | NO   |     | NULL    |       |
  | exp_date    | date          | YES  |     | NULL    |       |
  +-------------+---------------+------+-----+---------+-------+
  </code></pre>
  
  <p>and I've been given a relationship mapping of</p>
  
  <pre><code>ContractNum primary key, foreign key references table contracts
  fips        primary key, foreign key references table country
  metric_id   primary key, foreign key references table metrics
  time_id     primary key, foreign key references table time
  </code></pre>
  
  <p>Its been modeled in the class</p>
  
  <pre><code>class ContractCountyMetrics(models.Model):
    contractnum = models.CharField(max_length=10L, db_column='ContractNum', primary_key = true) # Field name made lowercase.
    fips = models.CharField(max_length=5L)
    metric_id = models.IntegerField()
    time_id = models.IntegerField()
    value = models.DecimalField(max_digits=14, decimal_places=3)
    eff_date = models.DateField()
    exp_date = models.DateField(null=True, blank=True)
    contractKey = models.ForeignKey(Contracts)
    fipsKey = models.ForeignKey(Counties)
    metricKey = models.ForeignKey(Metrics)
    timeKey = models.ForeignKey(Time)
    class Meta:
        db_table = 'txn_contract_county_metrics'
        unique_together("contractKey", "fipsKey", "metricKey", "timeKey")
  </code></pre>
  
  <p>From what I read, <code>unique_together</code>basically simulates a composite key and allows more than one field to have primary key functionality.  Am I on the right track? </p>