title: Django admin: Making a required field read-only
body: <p>I have a number of models with a ForeignKey relationship to a <code>Person</code> model.  For example:</p>
  
  <pre><code>class PersonData(BaseModel):
      person = models.ForeignKey(Person)
      data = models.TextField()
  </code></pre>
  
  <p>I want to lock down the admin such that once a <code>PersonData</code> object is created, an admin user can change the data, but can't change the <code>Person</code>. </p>
  
  <p>At first it seemed pretty straightforward -- I put this in the <code>PersonDataAdmin</code> class:</p>
  
  <pre><code>def get_readonly_fields(self, request, obj=None):
      if obj:
          return self.readonly_fields + ('person',)
      return self.readonly_fields
  </code></pre>
  
  <p>On the display side, that worked as expected -- I see the value for <code>person</code>, but it's grayed out so I can't change it -- but then when I try to change the data and submit the form, I get an error message, "Please correct the error below."  No other message appears, but with a bit of digging, I discovered that the form is missing a value for the required <code>person</code> field.</p>
  
  <p>I've investigated a solution that would involve creating a custom form that would disable this field selectively (something like <a href="https://stackoverflow.com/questions/324477/in-a-django-form-how-do-i-make-a-field-readonly-or-disabled-so-that-it-cannot">this</a> or <a href="https://stackoverflow.com/questions/4945802/how-can-i-disable-a-model-field-in-a-django-form">this</a>), but (a) I wasn't successful in getting it to work, and (b) it seemed like a ton of code for what seems like a much simpler situation.  I also looked into using <code>exclude</code>, but ran into the same problem as <code>read_only</code>.</p>
  
  <p>Any ideas for how to accomplish this?  Thank you!</p>