I'm listing a model in Django's admin via a TabularInline
. Inside this inline, I'd like to use Django's model traversal syntax to list data in other models referenced from this model via foreign keys. e.g.
class MyRelatedModel(models.Model):
name = models.CharField(max_length=50)
created = models.DateField(auto_now_add=True)
other = models.ForeignKey('MyOtherRelatedModel')
class MyOtherRelatedModel(models.Model):
name = models.CharField(max_length=50)
created = models.DateField(auto_now_add=True)
class MyRelatedModelInline(admin.TabularInline):
model = MyRelatedModel
fields = ['name', 'created', 'other__name']
#readonly_fields = ['name', 'created', 'other__name']
However, the usage of 'other__name' throws the ImproperlyConfigured error:
'MyRelatedModelInline.fields' refers to field 'other__name' that is missing from the form
Is the model traversal syntax not supported in ModelAdmin instances? If it is supported, what am I doing wrong?
EDIT: If I uncomment readonly_fields, the error becomes:
Caught AttributeError while rendering: 'MyMainModelAdmin' object has no attribute '__name__'