ModelAdmin for model with InlineModelAdmin for proxy class reference results in admin.E202
This is similar to #30273 and #32975. A class references a proxy model, and we define an inline for the proxied model. This fails with admin.E202 because Django does not recognize that the FK to the proxy model is the same as an FK to the proxied model.
Assume models as follows:
class Reporter(models.Model):
name = models.CharField(max_length=50)
class Journalist(Reporter):
class Meta:
proxy = True
class Article(models.Model):
reporter = models.ForeignKey(Journalist, on_delete=models.CASCADE)
and an admin as follows:
class ArticleInline(admin.TabularInline):
model = Article
fk_name = 'reporter'
@admin.register(Reporter)
class ReporterAdmin(admin.ModelAdmin):
inlines = [ArticleInline]
This will result in <class 'testapp.admin.ArticleInline'>: (admin.E202) fk_name 'reporter' is not a ForeignKey to 'testapp.Reporter'.
The problem seems to be that the parent list does not include the model itself, and as such Django does not recognize the equality here.
Change History
(9)
Component: |
Uncategorized → Database layer (models, ORM)
|
Triage Stage: |
Unreviewed → Accepted
|
Component: |
Database layer (models, ORM) → contrib.admin
|
Owner: |
changed from nobody to Antoine Cheneau
|
Status: |
new → assigned
|
Needs tests: |
set
|
Patch needs improvement: |
set
|
Needs tests: |
unset
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Was able to reproduce this on my end.