title: How can I restrict the choices to related object in django?
body: <p>I am trying to use django to organize and manage my clinical research data. I think I can get by with just the admin interface, since this is a behind-the-scenes database that does not need to go public. I can program, but never in python before, so I am getting stuck on simple things.</p>
  
  <p>I have Patients who make multiple Visits. Each Visit involves multiple Scans. In the admin interface, I can see all the Visits and all the Scans, as inlines on each Patient's page. However, when adding a new Scan, how can I make it so that the choice of which Visit to associate it with is limited to Visits for the Patient in question, not other Patients?</p>
  
  <p>Models (simplified):</p>
  
  <pre><code>class Patient(models.Model):
    patient_id = models.CharField(max_length=16, primary_key=True)
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)
  
  class Visit(models.Model):
    patient = models.ForeignKey(Patient)
    visit_date = models.DateTimeField()
  
  class Scan(models.Model):
    patient = models.ForeignKey(Patient)
    visit = models.ForeignKey(Visit)
    scan_type = models.CharField(max_length=32)
  </code></pre>
  
  <p>Thanks a lot for any help...</p>