title: Using get_readonly_fields in the admin for a model with a @property
body: <p>I'm flummoxed by the following:</p>
  
  <p>models.py</p>
  
  <pre><code>class MyModel(models.Model):
      ...
      @property
      def xyz(self):
          return ...
  </code></pre>
  
  <p>admin.py:</p>
  
  <pre><code>class MyModelAdmin(admin.ModelAdmin):
      readonly_fields = ("xyz",)
      ...
      def get_readonly_fields(self, request, obj=None):
          """ As per http://stackoverflow.com/a/13818017/1149759 """
          if &lt;some condition&gt;:
              return [f.name for f in self.model._meta.fields]
          return self.readonly_fields
  </code></pre>
  
  <p>If <code>&lt;some condition&gt;</code> is satisfied, the admin page for this model fails with:</p>
  
  <pre><code>Unknown field(s) (xyz) specified for MyModel. 
  Check fields/fieldsets/exclude attributes of class MyModel.
  </code></pre>
  
  <p>I tried refactoring the model and admin code to make xyz() not a property, but this same error happened in the same way.  </p>
  
  <p>Even tried stepping through the internal Django code.  It's failing on this line:</p>
  
  <pre><code>lib/python2.7/site-packages/django/contrib/admin/options.py(640)get_form()
  -&gt; return modelform_factory(self.model, **defaults)
  
  {'fields': [..., 'xyz', ...], 
    'formfield_callback': &lt;functools.partial object at 0x104a024c8&gt;, 
    'form': &lt;class 'django.forms.widgets.ModelForm'&gt;, 
    'exclude': [&lt;a long list of fields that does not include xyz&gt;]}
  </code></pre>
  
  <p>Thanks for any insight you can provide.</p>
  
  <p><strong>Update:</strong></p>
  
  <ul>
  <li>Removing <code>xyz</code> from <code>readonly_fields</code> doesn't fix things</li>
  <li>Tried eliminating <code>readonly_fields</code> altogether as per comment below.  The following also did not work:</li>
  </ul>
  
  <p><code>
         def get_readonly_fields(self, request, obj=None):
             if &lt;whatever&gt;:
                 return [f.name for f in self.model._meta.fields]
             return ['xyz', ...]
  </code></p>
  
  <p><strong>After additional testing, it begins to seem to me that there is no way that <code>get_readonly_fields</code> will work on this model!</strong>  </p>
  
  <pre><code>class MyModelAdmin(admin.ModelAdmin):
      # readonly_fields = ("xyz",) # Removed this field to test
      ...
      def get_readonly_fields(self, request, obj=None):
          return [] # Removed all the logic 
  </code></pre>
  
  <p>The preceding <em>still</em> throws the <code>Unknown fields specified</code> for <code>xyz</code> -- as well as for the following two fields on the model!</p>
  
  <pre><code>added = models.DateTimeField(auto_now_add=True, null=True, blank=True,)
  last_updated = models.DateTimeField(auto_now=True, null=True, blank=True,)
  </code></pre>